使用模板助手和模板变量(不正确的术语?)有什么区别?你什么时候决定使用哪个?
在下面的示例中,Template.apple.price
函数和 Template.apple.helpers
中的 quantity
函数似乎都在执行一样。
<template name="apple">
{{price}}
{{quantity}}
</template>
Template.apple.price = function() {
return 20;
}
Template.apple.helpers({
'quantity': function() {
return 100;
}
});
最佳答案
无,如 this section of the docs 中所述.唯一的区别是第二种方式允许你使用更多的关键词。例如,您不能这样做:
Template.foo.events = function() { /*...*/ };
但是你可以这样做:
Template.foo.helpers({
"events": function() { /*...*/ }
});
关于javascript - Meteor.js 中模板助手和模板变量的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130849/