HP.*_*HP. 6 html javascript jquery javascript-framework handlebars.js
我试图找到一种方法来解析不同的数据索引作为奇数或偶数
我正在看这个http://assemble.io/helpers/helpers-comparison.html并希望找到这样的东西:
{{#each array}}
{{#if_odd {{@index}}}}
{{this}} is odd
{{else}}
{{this}} is even
{{/if_odd}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
我并不真正关心语法,但希望我的想法能够实现.有帮助吗?谢谢.
HP.*_*HP. 23
我创建了这个帮手,它起作用了
Handlebars.registerHelper('if_even', function(conditional, options) {
if((conditional % 2) == 0) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Run Code Online (Sandbox Code Playgroud)
只需遵循条件助手http://handlebarsjs.com/block_helpers.html
我试图根据mu is too short建议这样做:
{{#if_even @index}}
Run Code Online (Sandbox Code Playgroud)