How to execute helper function after DOM is ready in meteor

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

      The reason why it returns null as a result is, you have placed it in Meteor.startup(). It actually runs before the data is loaded from the server. So the lists.find() returns null.

      The Meteor.startup() is a place for initializing your global variables, reative sessions and subscribing to the primary bunch of data from the server. Everything you write there will be executed once, right after the client starts up.

      The Template.myTemplate.rendered() is a special helper provided by meteor that runs everytime when the corresponding data has changed, it is mainly used for getting attributes or manipulating DOM elements contained within that template.

      So, place your helper code outside in common isClient() area. And use .rendered()helper to traverse the DOM, and getting or manipulating attributes of DOM elements.

    提交回复
    热议问题