How to execute helper function after DOM is ready in meteor

后端 未结 4 2058
一向
一向 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:03

      The best way to do this is to put code into Template.x.rendered() and use a Session reactive variable to track if the code has been run or not. For example, you could go about this like so:

      Template.x.rendered = function () {
        if (Session.get('doneMarkers') == null) {
          // Do your stuff
          if (getMarkers() != null) {
            Session.set('doneMarkers', 'yes');
          }
        }
      });
      
      function getMarkers() {
        var coordinates = {};
        coordinates = $('li.message').data();
        return coordinates;
      }
      

      If you ever want to rerun that part of the code, you only have to call:

      Session.set('doneMarkers', null);
      

    提交回复
    热议问题