data:
var people = [{
firstName: "Yehuda",
lastName: "Katz"
}, {
firstName: "Carl",
lastName: "Lerche"
}, {
firstName: "Alan",
lastName: "Johnson"
}, ];
response.render('index.hbs', {
firstName: 'firstName',
people: people,
});
index.hbs
<h2>{{firstName}}</h2>
<ul>
{{#each people}}
<li>{{firstName}}++++{{this.firstName}} {{this.lastName}}</li>
{{/each}}
</ul>
在index.hbs
中使用了data.firstName
,以及循环 people
中也有firstName
变量,现在想在循环people
中输出data.firstName
,但输出的始终是people
中的firstName
键值。如何处理?
画外音:
本来使用hbs挺顺畅的,但在遍历对象中直接用对象的键、以及this、this.对象键都可以输出键值,这是有多乱!而且对象是数组的话,还多了个[[[[[[[[[[[@index](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)](/user/index)变量等等,真糟糕!
之前用的是jade,但无法配合emmet神器,果断舍弃。