我有一个基本的帖子流在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字符串的中间位置。 这是怎么回事?
I have a basic post stream running in Meteor that pulls from the Posts collection. The template is feed by the following template helper that reaches into the collection:
Template.postStream.helpers({ /* Supplies posts collection to the client * view. */ postsStream: function(){ var loggedUser = Meteor.user(); return Posts.find({ userID: loggedUser._id }); }, });The helper seems to all work fine and the posts appear as expected. However, I get this vague error in the console and I can't work out how to clear it: Exception in template helper: postsStream@http://localhost:3000/client/views/stream/post-stream.js?37c902af708ff817888efc24c4e45f352cfb6884:6:41
Character 6:41 corresponds to midway through the loggedUser._id string. What's going on?
最满意答案
当第一次运行你的应用程序时,助手将被执行, Meteor.user()返回null因为登录恢复过程需要几毫秒。
你需要一个警卫来防止访问loggedUser._id ,否则你会得到一个异常。
return Posts.find({ userID: loggedUser && loggedUser._id });When first running your application, the helper will get executed with Meteor.user() returning null because the login resume process takes a few milliseconds.
You need a guard to prevent access to loggedUser._id, otherwise you'll get an exception.
return Posts.find({ userID: loggedUser && loggedUser._id });更多推荐
发布评论