Meteor `onRendered` only called once

北慕城南 提交于 2020-01-01 12:01:13

问题


After many hours of experimentation and reading I still don't understand why myTemplate.onRendered(function() {...}) is only called once.

Depending on where you read you get different information but it should apparently get called every time the inner HTML changes - that does not happen in my experiments it is only called once and never again no matter what I do.

Reactive dependencies do not seem to make it get called either (e.g. using Meteor.user() inside the onRendered callback).


回答1:


onRendered is only executed on the first render of the template and it is not reactive. To use reactive computations associated with a Template you should use template helpers or template.autorun.

It also seems you have an XY problem, try asking a different question with your feature in mind.




回答2:


That's normal. A template instance only gets rendered once. If you display multiple instances (in a loop) then each instance triggers its own onRendered once. If you destroy the instance and bring it back (switch menus or tabs) then you will trigger the onRendered again because the template really is being rerendered.



来源:https://stackoverflow.com/questions/29720716/meteor-onrendered-only-called-once

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!