问题描述
经过数小时的实验和阅读,我仍然不明白为什么 myTemplate.onRendered(function() {...})
只被调用一次.
After many hours of experimentation and reading I still don't understand why myTemplate.onRendered(function() {...})
is only called once.
根据您阅读的位置,您会获得不同的信息,但显然每次内部 HTML 更改时都应该调用它 - 在我的实验中不会发生这种情况,它只被调用一次,无论我做什么都不会再调用.
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.
响应式依赖似乎也没有让它被调用(例如在 onRendered
回调中使用 Meteor.user()
).
Reactive dependencies do not seem to make it get called either (e.g. using Meteor.user()
inside the onRendered
callback).
推荐答案
onRendered
仅在模板的第一次渲染时执行,它不是响应式的.要使用与 Template
关联的反应式计算,您应该使用 模板助手 或 template.autorun
.
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
.
您似乎也遇到了XY 问题,请尝试提出不同的问题对您的功能提出问题.
It also seems you have an XY problem, try asking a different question with your feature in mind.
这篇关于Meteor `onRendered` 只调用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!