Meteor.js中的模板助手和模板variables之间的区别

使用模板助手和模板variables(不正确的术语?)有什么区别? 你什么时候决定使用哪一个?

在下面的例子中, Template.apple.price函数和Template.apple.pricequantity函数看起来都是一样的。

 <template name="apple"> {{price}} {{quantity}} </template> Template.apple.price = function() { return 20; } Template.apple.helpers({ 'quantity': function() { return 100; } }); 

没有什么,如本文档中所述 。 唯一的区别在于第二种方式允许您使用更多的关键字。 例如,你不能这样做:

 Template.foo.events = function() { /*...*/ }; 

但是你可以这样做:

 Template.foo.helpers({ "events": function() { /*...*/ } });