Javascript 流星模板是';不能正确渲染
我正在构建一个通知页面,用户可以在其中看到哪些帖子有评论,我想显示每个帖子的日期,但它不起作用 代码如下:Javascript 流星模板是';不能正确渲染,javascript,meteor,handlebars.js,Javascript,Meteor,Handlebars.js,我正在构建一个通知页面,用户可以在其中看到哪些帖子有评论,我想显示每个帖子的日期,但它不起作用 代码如下: <template name="notification"> <li><a href="{{notificationPostPath}}">Someone commented your post, {{postDate}}</a> </li> </template> Template.notificat
<template name="notification">
<li><a href="{{notificationPostPath}}">Someone commented your post, {{postDate}}</a> </li>
</template>
Template.notification.helpers({
notificationPostPath: function() {
return Router.routes.PostPage.path({_id: this.postId});
},
post: function () {
return Post.findOne({_id: this.postId});
},
postDate: function() {
return moment(post.submitted).format('dddd, MMMM Do');
}
});
Template.notification.helpers({
notificationPostPath:函数(){
返回Router.routes.PostPage.path({u id:this.postId});
},
职位:职能(){
return Post.findOne({u id:this.postId});
},
postDate:函数(){
返回时刻(提交后)。格式(“dddd,MMMM Do”);
}
});
控制台打印以下内容:来自Deps的异常重新计算:引用错误:未定义post
提前感谢我假设错误标记在以下行:
return moment(post.submitted).format('dddd, MMMM Do');
请注意,您不能从其他帮助程序中引用这样的帮助程序(无论如何,post
是一个函数)-您还需要在postDate
帮助程序的开头添加另一行,如下所示:
var post = Post.findOne({_id: this.postId});