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

StackOverflow https://stackoverflow.com/questions/22346261

  •  13-06-2023
  •  | 
  •  

문제

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