How to execute helper function after DOM is ready in meteor

后端 未结 4 2069
一向
一向 2021-02-01 08:42

I have a list of

  • \'s which gets populated with a find() using Meteor.startup as you see below. Then I\'m getting all the data attributes of these &l
  • 4条回答
    •  庸人自扰
      2021-02-01 09:02

      Many thanks Akshat for detailed answer)

      I have more complicated case of using Meteor.subscribe, i have template which includes images from DB. So i need to wait for data from two collection iamges and news(all other data here).

      I get my DOM ready in this way:

      imageIsLoaded = new Promise(function(resolve){
          Meteor.subscribe('images',function(){
              resolve()
          });
      });
      
      newsIsLoaded = new Promise(function(resolve){
          Meteor.subscribe('news',function(){
              resolve()
          });
      });
      
      
      Template.newsList.onRendered(function(){
          Promise.all([imageIsLoaded, newsIsLoaded]).then(function() {
              // DOM IS READY!!!
              newsServices.masonryInit();
          })
      });
      

      Template structure:

      
      

    提交回复
    热议问题