How do you send info from 2 different collections to one route in iron-router for meteor?

For example I have a Posts and Comments collection and wanted to assign both Posts.findOne(this.params._id) and Comments.find({postId: this.params._id}) to the data field of route detailedPost route so that I could display both the post details and the comments for that post.

有帮助吗?

解决方案

You can easily assign them to parameters of the data object:

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}),
      };
    },
  });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top