javascript - Meteor.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.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/

相关文章:

node.js - 未处理的 promise 拒绝警告 : Mongoose Server Selection Error

javascript - 将 shopify 购买按钮添加到 meteor js 网站

linux - 如何在Meteor中安装Meteorite?

javascript - 在 Javascript HTML 中使用带有部分地址的 if 语句

javascript - node.js promise : how to find out which iteration threw the exception in a . catch 语句?

node.js - knex SQL - 列必须出现在 GROUP BY 子句中或在聚合函数中使用

node.js - 亚马逊 MWS SubmitFeed Content-MD5 HTTP header 与亚马逊计算的 Content-MD5 不匹配

JavaScript 隐藏/可见脚本在第二次点击后不隐藏

javascript - 如何隐藏/显示钛合金文本字段?

javascript - 变量在一个 JS 文件的多个 HTML 文件中持续存在的问题