Javascript Meteor.js中模板助手和模板变量之间的差异
使用模板帮助器和模板变量(不正确的术语?)之间有什么区别?你什么时候决定用哪个 在下面的示例中,Javascript Meteor.js中模板助手和模板变量之间的差异,javascript,node.js,meteor,handlebars.js,Javascript,Node.js,Meteor,Handlebars.js,使用模板帮助器和模板变量(不正确的术语?)之间有什么区别?你什么时候决定用哪个 在下面的示例中,Template.apple.price函数和Template.apple.helpers中的quantity函数似乎都做同样的事情 <template name="apple"> {{price}} {{quantity}} </template> Template.apple.price = function() { return 20; }
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;
}
});
{{price}}
{{数量}}
Template.apple.price=函数(){
返回20;
}
Template.apple.helpers({
“数量”:函数(){
返回100;
}
});
没有,如中所述。唯一的区别是,第二种方式允许您使用更多的关键字。例如,您不能这样做:
Template.foo.events = function() { /*...*/ };
但你可以这样做:
Template.foo.helpers({
"events": function() { /*...*/ }
});
区别是什么?在第一个示例中,不能将保留关键字用作键。虽然你也不想在第二种情况下使用它们。