Meteor JS Template rendered function called before template is rendered?

前端 未结 1 1578
后悔当初
后悔当初 2020-12-12 04:52

I\'m trying to use the Buttonset widget in JQuery UI. I\'ve got the package loaded and my template renders the radio buttons fine. I have a \"rendered\" function to call the

相关标签:
1条回答
  • 2020-12-12 05:34

    rendered only works for elements which will appear in the DOM the very first time the template is added to the page. Assume that subscription data takes infinitely long to arrive, then look at the template and see which elements would appear in the default state.

    Using the leaderboard example, we can't assume that players are available when the leaderboard template renders (it depends on a subscription). To target a player, you should use the rendered callback on the player template.

    It's hard to generalize a strategy for when to apply jQuery plugins, but here are some ideas:

    • Use the rendered callback if the element will always be added in the default state (e.g. the element is hard-coded and doesn't depend on a conditional).

    • Use the rendered callback of the most specific child template to target that child (e.g. the player template from above).

    • Consider using an event handler callback to target the element if it's appearance depends on an event (e.g. a button click).

    • Consider using a template autorun callback to target the element if it's appearance depends on reactive state. See this question for an example.

    0 讨论(0)
提交回复
热议问题