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