[英]Meteor template isn't rendering properly
我正在構建一個通知頁面,用戶可以在其中看到哪些帖子有評論,並且我想顯示每個帖子的日期,但是它不起作用。
這是代碼:
<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');
}
});
控制台將打印以下內容:Deps重新計算異常:ReferenceError:帖子未定義。
提前致謝
我假設錯誤在以下行中被標記:
return moment(post.submitted).format('dddd, MMMM Do');
請注意,您不能像這樣從其他助手中引用助手(無論如何, post
是一個函數)-您也需要在postDate
助手的開頭添加另一行,如下所示:
var post = Post.findOne({_id: this.postId});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.