我正在迭代一个数组对象express-handlebars
,并且只有每个创建的第二个 dom 元素应该具有特定的属性。
像这样的东西:
<div class=""></div>
<div></div>
<div class=""></div>
<div></div>
我注意到有一个@size
包含迭代索引的值。
到目前为止,我的代码如下所示:
{{#each todoGroups}}
{{#if @index}}
<div class=""></div>
{{/if}}
{{/each}}
但是如何在 if 语句中添加一个条件,该条件只对true
每个第二项进行评估?
我一直在尝试实现此功能,这是我目前的方法:
function hbsHelpers(hbs) {
return hbs.create({
helpers: { // This was missing
isEven: function(value, options) {
},
// More helpers...
},
});
}