在基於模板的小部件中,我在模板中有一個表。該表的主體將被構建 在我的小部件中使用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 ");
},
是。你需要解析''元素。 'lang.replace'只用於字符串替換。該事件將在解析後附加。或者你也可以使用'dojo/on'模塊來附加事件。在這種情況下,不需要解析。 – Himanshu
感謝Himansh。你能告訴我如何改變代碼嗎?我改變了我的代碼,但沒有再發生。新代碼: – ehsanpaknahad
請分享您的更新代碼。 – Himanshu