gpt4 book ai didi

meteor - 渲染 meteor 雨中所有模板的回调

转载 作者:行者123 更新时间:2023-12-04 04:21:34 25 4
gpt4 key购买 nike

我被迫将渲染的回调分配给所有模板。

直到0.9.0,我以前都是这样的:

_.each( Template, function( template, name ) {
//...
template.rendered = function() {
//...
};
});

但是现在,Template是一个构造函数,而不是一个对象,因此此方法在这里不起作用。使用Blaze渲染所有模板时,是否可以将回调函数传递给所有模板或触发函数?

最佳答案

这是我想出的一个快速解决方法,它遍历每个Template属性以找出它是否对应于模板定义,如果确实如此,则分配onRendered回调。

// make sure this code is executed after all your templates have been defined
Meteor.startup(function(){
for(var property in Template){
// check if the property is actually a blaze template
if(Blaze.isTemplate(Template[property])){
var template=Template[property];
// assign the template an onRendered callback who simply prints the view name
template.onRendered(function(){
console.log(this.view.name);
});
}
}
});

我不知道您的用例是什么,因此可能有更好的解决方案。

关于meteor - 渲染 meteor 雨中所有模板的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26281201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com