In Meteor, how can I query only the records of a given subscription?

前端 未结 3 1653
北海茫月
北海茫月 2020-12-18 07:09

I understand that a a subscription is a way to flow records into a client-side collection, from this post, and others...

However, per this post, You can have multipl

3条回答
  •  悲哀的现实
    2020-12-18 07:46

    Of course! It just depends on where you write your subscriptions. In a lot of cases you might be using Iron Router, in which case you would have a given route subscribe to just the data that you need. Then from within that route template's helper you can only query documents within that subscription.

    But the general idea is that you hook up a particular subscription to a particular template.

    Template.onePost.helpers({
      post: function() {
        Meteor.subscribe('just-one-post', );
        return Posts.findOne();
      }
    });
    
    Template.allPosts.helpers({
      posts: function() {
        Meteor.subscribe('all-posts');
        return Posts.find();
      }
    ));
    

提交回复
热议问题