handlebars 对if 判断的能力较弱,往往难以满足项目要求,可以通过注册if 来达到要求,如下:
define(['handlebars'], function (handlebars) { //注册判断器 handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { switch (operator) { case '!=': return (v1 != v2) ? options.fn(this) : options.inverse(this); break; case '==': return (v1 == v2) ? options.fn(this) : options.inverse(this); break; case '===': return (v1 === v2) ? options.fn(this) : options.inverse(this); break; case '<': return (v1 < v2) ? options.fn(this) : options.inverse(this);