[英]Meteor template isn't rendering properly
I'm building a notifications page, where the user can see which posts have comments, and I want to display the date of each post, but it's not working. 我正在构建一个通知页面,用户可以在其中看到哪些帖子有评论,并且我想显示每个帖子的日期,但是它不起作用。
Here is the code: 这是代码:
<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');
}
});
The console prints this: Exception from Deps recompute: ReferenceError: post is not defined. 控制台将打印以下内容:Deps重新计算异常:ReferenceError:帖子未定义。
Thanks in advance 提前致谢
I assume the error is being flagged on the following line: 我假设错误在以下行中被标记:
return moment(post.submitted).format('dddd, MMMM Do');
Note that you can't refer to helpers from within other helpers like that (and anyway, post
is a function) - you need too add another line at the start of the postDate
helper like this: 请注意,您不能像这样从其他助手中引用助手(无论如何,
post
是一个函数)-您也需要在postDate
助手的开头添加另一行,如下所示:
var post = Post.findOne({_id: this.postId});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.