【问题标题】:Difference between Template Helper and Template Variable in Meteor.jsMeteor.js 中模板助手和模板变量的区别
【发布时间】:2013-12-06 12:08:58
【问题描述】:

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

在下面的示例中,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;
    }
});

【问题讨论】:

    标签: javascript node.js meteor handlebars.js


    【解决方案1】:

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

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

    但你可以这样做:

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

    【讨论】:

    • 有什么区别?
    • 第一个示例中不能使用保留关键字作为键。虽然您也不想在第二次使用它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2015-01-15
    • 2015-01-06
    • 2018-10-12
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多