【发布时间】:2015-10-22 12:17:54
【问题描述】:
我正在尝试显示当前登录用户的帖子。我尝试了与在相关帖子页面下显示 cmets 相同的方法,但不适用于已登录用户的帖子。
Template.myPosts.helpers({
posts: function () {
selector = {userId: this.userId};
options = {sort: {createdAt: -1}};
return Posts.find(selector, options);
}
});
我还在 router.js 中尝试了下面的代码(安装了铁路由器包):
this.route('myPosts', {
path:'/my-posts',
data:function(){
return Posts.find({userId: this.userId})
}
});
})
如果上面的代码不接近应有的样子,任何有关如何进行的提示将不胜感激。这是一个仅用于学习目的的项目。
谢谢!
【问题讨论】:
-
你也有订阅和发布代码吗?
-
@k.chao.0424 我也试过了。在过去的 4-5 小时里,我一直在尝试使用不同(著名)包的不同方法,但仍然失败。
标签: meteor