无法访问部分车把中的对象属性

问题描述 投票:1回答:1

我正在开发nodejs应用程序。并想在网页上显示猫鼬结果。模板引擎是快速车把。

   data=  [
              {name: 'some name', image: '/some_name.jpg', location: 'some location'},
              {name: 'some name2', image: '/some_name2.jpg', location: 'some location2'},
              {name: 'some name3', image: '/some_name3.jpg', location: 'some location3'}
           ]

我想部分渲染把手中的数据。首先,我使用#each迭代每个对象,并将该对象传递给局部对象。下面是我的代码。

{{#each data}}
   {{> somePartial this}} 
{{/each}}

somePartial中,我想访问对象的属性。

 <h5>Name: {{this.name}}</h5>
 <h5>Image: {{this.image}}</h5>
 <h5>Location: {{this.location}}</h5>

我在浏览器中看不到任何值呈现。在服务器控制台中,我收到一些警告或类似的内容Handlebars:由于属性不是其父项的“拥有的属性”,所以拒绝访问以解析属性“ xxxx”。

node.js express handlebars.js partials express-handlebars
1个回答
0
投票

仅使用不带this

{{> somePartial}} 

...

<h5>Name: {{name}}</h5>

此处有更多信息:https://handlebarsjs.com/guide/partials.html#partial-parameters

© www.soinside.com 2019 - 2024. All rights reserved.