我有一個包含少量元素(輸入,radioButton等)的模板。如果我想獲得MyTemplate的內這些DOM元素我可以活動如何訪問Template.myTemplate.events,Template.myTemplate.rendered等外部聲明的DOM元素
Template.myForm.events({
'click #submitButton' : function (event, template) {
//template variable here gives me access to the
//current template instance, so I can get to any
//DOM element within this template.
}
})
或在
Template.myForm.rendered = function() {
//within this function I have access to "this" which points to template instance
}
我想知道如果有一種方法來訪問DOM元素,一個聲明中訪問它們在這些事件函數之外的模板中並呈現回調?
在此先感謝
除了呈現回調可以改變的模板實例也可以在創建的(this不可用)中使用'this'並銷燬回調。在助手中,可以使用'Template.instance()',但是在第一次調用助手時,DOM將不可用。這通常應該是訪問模板DOM所需的所有位置。否則,可能有更簡單的方法來解決你試圖做的任何事情。請記住,流星有利於使用JavaScript結構存儲數據,而不是將其存儲在DOM中。 – sbking 2014-12-04 08:55:07
感謝您的洞察力......將數據存儲在Javascript結構中而不是DOM中 – Taimoor 2014-12-04 22:51:26