Meteor.js中模板助手和模板变量的区别

时间:2013-11-21 20:05:40

标签: javascript node.js meteor handlebars.js

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

在下面的示例中,Template.apple.price函数和quantity中的Template.apple.helpers函数似乎都做同样的事情。

<template name="apple">
    {{price}}
    {{quantity}}
</template>



Template.apple.price = function() {
    return 20;
}

Template.apple.helpers({
    'quantity': function() {
        return 100;
    }
});

1 个答案:

答案 0 :(得分:3)

没有,如this section of the docs中所述。唯一的区别是第二种方式允许您使用更多关键字。例如,你不能这样做:

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

但你可以这样做:

Template.foo.helpers({
    "events": function() { /*...*/ }
});
相关问题