在 meteor 中,我可以像这样设置各种模板助手:
Template.story.title = function () {
return "title";
};
<template name="story">
<h3>{{title}}</h3>
<p>{{description}}</p>
</template>
这很好,但是,如果我有很多变量,我不想单独设置它们,我想将上下文传递给主模板。
我该怎么做?
Template.story.data = function () {
return {title:"title", description:"desc"};
};
<template name="story">
<h3>{{title}}</h3>
<p>{{description}}</p>
</template>
那是行不通的。谢谢
最佳答案
调用时可以设置模板的上下文:
{{> story data}}
Template.outerTemplate.data = function() {
return {title:"title", description:"desc"};
}
或者你可以使用 {{#with}}
动态设置模板上下文:
{{#with data}}
{{title}}
{{/with}}
关于javascript - Meteor 设置整体模板上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13005890/