Ada*_*ski 9 meteor meteor-blaze
我被迫将渲染的回调分配给我的所有模板.
直到0.9.0我曾经这样做:
_.each( Template, function( template, name ) {
//...
template.rendered = function() {
//...
};
});
Run Code Online (Sandbox Code Playgroud)
但是现在,Template是一个构造函数而不是一个对象,所以这个方法在这里不起作用.当使用Blaze渲染所有模板时,有没有办法将回调函数传递给所有模板或fire函数?
这是我提出的一个快速解决方法,迭代每个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);
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
我不知道你的用例是什么,所以根据它可能有更好的解决方案.
归档时间: |
|
查看次数: |
1537 次 |
最近记录: |