Meteor: How can I tell when the database is ready?

后端 未结 6 942
醉话见心
醉话见心 2020-12-01 11:39

I want to perform a Meteor collection query as soon as possible after page-load. The first thing I tried was something like this:

Games = new Meteor.Collecti         


        
6条回答
  •  天命终不由人
    2020-12-01 12:02

    You can also do template level subscriptions:

    Template.name.onCreated(function(){
    var self = this;
    
    this.autorun(function(){
    
    const db = this.subscribe('publicationname', [,args]);
    
    if(db.isReady()){
     "You'll know it's ready here" .. do what you need.
     }
     });
    })
    

    This makes it easier to know inside the template too. you can just call {{#if Template.subscriptionsReady}} {{else}} Loading Screen may be
    {{/if}}

提交回复
热议问题