在 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>
那行不通。谢谢。
this
是默认上下文。应该有一种方法来设置this
而不是data
。谢谢。 - Harry