我必须在任何地方定义模板助手,以简单地测试文档属性与常量的相等性,以便我可以在模板中执行类似的操作:
{{#if fruitIsPineapple}}...{{/if}}
在我的模板助手中,它看起来像:
Template.example.helpers({
fruitIsPineapple: function () { return this.document.fruit === 'pineapple'; }
});
如何才能使自己免于创建所有这些助手?如果 Blaze 中有一个相等运算符就好了...
最佳答案
我的问题在 Meteor Devshop 得到了解答。结果你可以定义一个 Handlebars 助手,如下所示:
Template.registerHelper('equals', function (a, b) {
return a === b;
});
然后在前缀位置使用它,如下所示:
{{#if equals fruit 'pineapple'}}...{{/if}}
关于javascript - Meteor:在 Blaze 中测试两个值相等(例如 {{#if someVar == 'someVal' }})的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22705532/