流星模板没有正确渲染

Meteor template isn't rendering properly

本文关键字:流星      更新时间:2023-09-26

我正在构建一个通知页面,用户可以在其中看到哪些帖子有评论,我想显示每个帖子的日期,但它不工作。

代码如下:

<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的Exception from recompute: ReferenceError: post is not defined.

Thanks in advance

我假设错误被标记在以下行:

return moment(post.submitted).format('dddd, MMMM Do');

注意,你不能像这样从其他帮助器中引用帮助器(无论如何,post是一个函数)-你还需要在postDate帮助器的开头添加另一行,像这样:

var post = Post.findOne({_id: this.postId});