如何在meteor的iron router中将来自2个不同集合的信息发送到一条路由?
如何在meteor的iron router中将来自2个不同集合的信息发送到一条路由如何在meteor的iron router中将来自2个不同集合的信息发送到一条路由?,meteor,collections,iron-router,Meteor,Collections,Iron Router,如何在meteor的iron router中将来自2个不同集合的信息发送到一条路由 例如,我有一个Posts和Comments集合,希望同时分配Posts.findOne(this.params.\u id)和Comments.find({postId:this.params.\u id})发送到路线详细帖子的数据字段以便我可以显示帖子详细信息和该帖子的评论 您可以轻松地将它们分配给数据对象的参数: Router.map(function() { this.route('detailedPo
例如,我有一个
Posts
和Comments
集合,希望同时分配Posts.findOne(this.params.\u id)
和Comments.find({postId:this.params.\u id})
发送到路线详细帖子
的数据
字段以便我可以显示帖子详细信息和该帖子的评论 您可以轻松地将它们分配给数据
对象的参数:
Router.map(function() {
this.route('detailedPost', {
path: '/post/:id',
data: function() {
return {
post: Posts.findOne(this.params._id),
comments: Comments.find({postId: this.params._id}),
};
},
});
});
谢谢并给其他有同样问题的人一个提示,你可以在模板中使用{{{{with post}{{/with}}或{{{each comments}{/each}}或仅仅
{post.title}
,{post.body}
等方式访问它们。谢谢Hubert。我不知道,这很有帮助。我在Meteor上找到的所有文档都有路由器端的示例,但没有如何访问事物的模板端,所以这在某些地方是需要的。