2017-04-11 42 views
0

在基於模板的小部件中,我在模板中有一個表。該表的主體將被構建 在我的小部件中使用domConstruct。問題在於「a」元素 的點擊事件不起作用。當我點擊它並且記錄沒有顯示任何錯誤或消息時(我的模板中的其他單擊事件工作正常),實際上沒有任何反應,問題只在於以編程方式使用domConstruct創建的事件。 (這是可能的,我應該解析「一」 elemet?如果這是正確的,我不知道該怎麼做。)dojo - 模板中的單擊事件不起作用

for (var i = 0; i < result.features.length; i++) { 
    domConstruct.place(lang.replace('<tr><td><a class="zoomto" data-dojo-attach- event="ondijitclick:zoomto">{t0}</a></td><td>{t1}</td><td>{t2}</td><td>{t3}</td></tr>',{ 
    t0:i + 1, 
    t1:result.features[i].attributes.rent, 
    t2:result.features[i].attributes.OBJECTID, 
    t3:result.features[i].attributes.ACCT 
}), this.rowNode); 

} 


….. 

zoomto: function() {  
    console.log("zoomto is clicked "); 
}, 
+0

感謝Himansh。你能告訴我如何改變代碼嗎?我改變了我的代碼,但沒有再發生。新代碼: – ehsanpaknahad

+0

請分享您的更新代碼。 – Himanshu

回答

0

您需要可以解析<a>元素或使用dojo/on附着事件。

for (var i = 0; i < result.features.length; i++) { 
    var element= domConstruct.toDom(lang.replace('<tr><td><a class="zoomto" data-dojo-attach-event="ondijitclick:zoomto">{t0}</a></td><td>{t1}</td><td>{t2}</td><td>{t3}</td></tr>',{ 
    t0:i + 1, 
    t1:result.features[i].attributes.rent, 
    t2:result.features[i].attributes.OBJECTID, 
    t3:result.features[i].attributes.ACCT 
})); 
domConstruct.place(element, this.rowNode); 

} 
dojo.parser.parse(this.rowNode); 

OR

for (var i = 0; i < result.features.length; i++) { 

    var element= domConstruct.toDom(lang.replace('<tr><td><a class="zoomto" >{t0}</a></td><td>{t1}</td><td>{t2}</td><td>{t3}</td></tr>',{ 
    t0:i + 1, 
    t1:result.features[i].attributes.rent, 
    t2:result.features[i].attributes.OBJECTID, 
    t3:result.features[i].attributes.ACCT 
})); 
dojo.on(element, 'ondijitclick', this.zoomto); 
domConstruct.place(element, this.rowNode); 

}