2012-08-08 108 views
1

我正在使用流星,所以有人可能會建議我可以在模板顯示(未加載)後處理的事件...?例如,我有一個顯示模式彈出窗口的模板。現在我想在模板「顯示」(未加載)後執行某些操作。請建議我如何處理相應的事件。 我都試過了,模板加載事件

<template name = "SendMessage"> 

//modal popup code 
{{check}} 
</template> 

Template.SendMessage.check = function(){ 
alert("load"); 
}; 
+0

請看看http://stackoverflow.com/questions/10109788/callback-after-the-dom-was-updated-in-meteor-js。它對你有用嗎? – 2012-08-09 02:21:36

回答

0

可以achive,在這個哈克的方式:

Template.SendMessage.check = function(){ 
    Meteor.defer(function(){ 
     //modal code 
    }); 
}; 

或者

Template.SendMessage.check = function(){ 
    setTimeout(function(){  
     //modal code 
    },0); 
}; 
1

的流星從0.4.0預覽開始更多的哈克,你可能想使用Template.myTemplate.rendered並使用布爾值來跟蹤Template對象中的狀態(因此,每次更新模板的一部分時都不會調用它):

Template.myTemplate.rendered = function() { 
    if(!this._rendered) { 
     this._rendered = true; 
     alert('load'); 
    } 
} 
0

假設你有一個呈現一次但想在url更改時反應的模板,如加載不同的模式等。 如果是這種情況,這是一種可能的方式。

Template.PageDetail.onRendered(function(){ 
    this.autorun(() => { 
     FlowRouter.watchPathChange(); 
     // do the thing! 
     yourFunction(); 
    }) 
})