比较 ==、>=、|| 等值,&&
创建一个助手来处理所有情况
Handlebars.registerHelper( "when",function(operand_1, operator, operand_2, options) {
var operators = {
'eq': function(l,r) { return l == r; },
'noteq': function(l,r) { return l != r; },
'gt': function(l,r) { return Number(l) > Number(r); },
'or': function(l,r) { return l || r; },
'and': function(l,r) { return l && r; },
'%': function(l,r) { return (l % r) === 0; }
}
, result = operators[operator](operand_1,operand_2);
if (result) return options.fn(this);
else return options.inverse(this);
});
在车把文件中使用此运算符例如。 == 运算符
{{#when <operand1> 'eq' <operand2>}}
// do something here
{{/when}}