如何知道Meteor包中的模板何时完成渲染

时间:2022-11-15 19:42:51

Is there an event/callback that could be used to monitor and run code just after a template from a third-party package has finished rendering? This is because I found that some packages render they content shortly after my other templates render and I would like to able to run code just after each one render. But if third-packages have their own subscriptions then I can't use the onReady callback that I use for my own subscriptions... So, does anyone know a simple way to do this?

是否有事件/回调可用于在第三方软件包的模板完成呈现后立即监视和运行代码?这是因为我发现一些包在我的其他模板渲染后很快就会呈现它们的内容,我希望能够在每次渲染之后运行代码。但是如果第三个包有他们自己的订阅,那么我就不能使用我用于我自己的订阅的onReady回调...所以,有没有人知道一个简单的方法来做到这一点?

1 个解决方案

#1


The solution is to use the onRendered template lifecycle event on the specific third party package template you want to track being rendered.

解决方案是在要跟踪的特定第三方包模板上使用onRendered模板生命周期事件。

Template.packageTemplate.onRendered(function(){
  //
});

Calling onRendered on a parent template that includes the package template won't work because it will trigger BEFORE its child package template own rendered event.

在包含包模板的父模板上调用onRendered将不起作用,因为它将触发BEFORE其子包模板自己的呈现事件。

#1


The solution is to use the onRendered template lifecycle event on the specific third party package template you want to track being rendered.

解决方案是在要跟踪的特定第三方包模板上使用onRendered模板生命周期事件。

Template.packageTemplate.onRendered(function(){
  //
});

Calling onRendered on a parent template that includes the package template won't work because it will trigger BEFORE its child package template own rendered event.

在包含包模板的父模板上调用onRendered将不起作用,因为它将触发BEFORE其子包模板自己的呈现事件。