【问题标题】:dojo - click event in template does not workdojo - 模板中的单击事件不起作用
【发布时间】:2017-04-11 06:12:15
【问题描述】:

在基于模板的小部件中,我在模板中有一个表格。表格的主体将被构建 在我的小部件中使用 domConstruct。问题是“a”元素的点击事件 不起作用。当我单击它并且日志记录未显示任何错误或消息时,实际上什么也没有发生。(我的模板中的其他单击事件工作正常)问题仅在于以编程方式使用 domConstruct 生成的此事件。 (有可能我应该解析“a”元素?如果它是正确的,我不知道该怎么做。)

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 ");
},

【问题讨论】:

  • 是的。您需要解析 &lt;a&gt; 元素。 lang.replace 仅用于字符串替换。解析后将附加该事件。或者你也可以使用dojo/on 模块来附加事件。在这种情况下,不需要解析。
  • 谢谢希曼什。你能告诉我如何更改代码吗?我改变了我的代码,但什么也没发生。新代码:
  • 请分享您的更新代码。
  • for (var i = 0; i {t0} {t1} {t2} {t3}' ,{ t0:i + 1, t1:result.features[i].attributes.rent, t2:result.features[i].attributes.OBJECTID, t3:result.features[i].attributes.ACCT }), 这个.rowNode); } zoomto: function () { console.log("zoomto is clicked"); }, postCreate: function(){ this.inherited(arguments); on(dom.byId("zoomID"), 'click', lang.hitch(this, this._zoomto)); } ,
  • 显示代码很乱

标签: templates events dojo widget click


【解决方案1】:

您需要解析&lt;a&gt; 元素或使用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);

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);

}
猜你喜欢
  • 1970-01-01
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
  • 2017-10-13
  • 2015-08-21
  • 2014-10-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多