【问题标题】:Meteor template isn't rendering properlyMeteor 模板未正确渲染
【发布时间】:2014-03-15 22:44:48
【问题描述】:

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

代码如下:

<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: post is not defined。

提前致谢

【问题讨论】:

    标签: javascript meteor handlebars.js


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-24
      • 2014-12-12
      • 1970-01-01
      • 2015-06-11
      • 1970-01-01
      • 2015-03-24
      • 2014-12-08
      • 2015-06-16
      相关资源
      最近更新 更多