【问题标题】:Meteor: "exception in template helper"流星:“模板助手中的异常”
【发布时间】:2015-09-05 08:18:03
【问题描述】:

我有一个在 Meteor 中运行的基本帖子流,它来自 Posts 集合。模板由以下模板帮助器提供,该帮助器到达集合中:

    Template.postStream.helpers({
        /* Supplies posts collection to the client
        *  view. */
        postsStream: function(){
            var loggedUser = Meteor.user();
            return Posts.find({ userID: loggedUser._id });
        },

    });

助手似乎一切正常,帖子按预期显示。但是,我在控制台中收到这个模糊的错误,我不知道如何清除它: Exception in template helper: postsStream@http://localhost:3000/client/views/stream/post-stream.js?37c902af708ff817888efc24c4e45f352cfb6884:6:41

字符 6:41 对应于 loggedUser._id 字符串的中途。怎么回事?

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    第一次运行您的应用程序时,帮助程序将被执行,Meteor.user() 返回null,因为登录恢复过程需要几毫秒。

    你需要一个守卫来阻止对loggedUser._id的访问,否则你会得到一个异常。

    return Posts.find({ userID: loggedUser && loggedUser._id });
    

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 2015-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      • 2015-06-11
      • 1970-01-01
      • 2018-05-19
      相关资源
      最近更新 更多