【发布时间】:2013-03-27 23:18:14
【问题描述】:
正如official meteor wiki about handlebars所说:
让一个帮助器对多个模板可见的唯一方法是为每个模板分配相同的函数,或者声明一个全局帮助器。
我正在使用telescope 构建应用程序,问题是用户配置文件中的“member since”的值缺失,如下图所示。
作为 /client/views/users/user_profile.js 中的源代码
Template.user_profile.createdAtFormatted = Template.user_item.createdAtFormatted;
效果不好。
这里是 /client/views/users/user_item.js Template.user_item 中的助手
Template.user_item.helpers({
createdAtFormatted: function(){
return this.createdAt ? moment(this.createdAt).fromNow() : '–';
})
,当我像这样更改 /client/views/users/user_profile.js 中的代码时:
Template.user_profile.createdAtFormatted = function() {
return this.createdAt ? moment(this.createdAt).fromNow() : '–';
}
或者做一个像这样的全局助手
Handlebars.registerHelper("createdAtFormatted", function(){
return this.createdAt ? moment(this.createdAt).fromNow() : '–';
});
那么,就这样就好了
我只想知道为什么Template.user_profile.createdAtFormatted = Template.user_item.createdAtFormatted; 的作业没有按我或作者希望的方式工作?
【问题讨论】:
标签: meteor