【发布时间】:2013-07-03 15:12:56
【问题描述】:
我正在将小部件添加到 ERSI 地图查看器项目中,该项目可在此 link 中找到。
所以我制作了一个带有 dijit/form/button 的查询小部件,并希望实现一个 dojo/on 事件监听器来监听它的点击事件。
按钮在 html 标记中声明为:
<button data-dojo-type="dijit.form.Button" id="searchButton" type="button">Submit</button>
在我的 JavaScript 中,在 postCreate 函数的末尾我有:
on(dojo.byId("searchButton"), "click", function execute() {
// Set the WHERE search text
this.findParams.searchText = dojo.byId("searchText").value;
// Sends a request to the ArcGIS REST map service resource to perform a search based
// on the FindParameters specified in the findParameters argument. On completion, the
// onComplete event is fired and the optional callback function is invoked.
this.findTask.execute(this.findParams, this.showResults, this.showError);
});
我收到一个 TypeError:_526 为空。这个错误似乎可以忽略不计,因为我知道我做错了。除了上面的代码,我尝试了几十个其他代码,没有任何效果。
我为dojo/on 找到的所有示例都没有显示如何执行此特定应用程序。
我对 dojo 还是很陌生,我只是在这个项目上,直到我可以解决另一个同事遇到的一些问题,但是如果有人可以给我展示一个示例或链接到一个示例来说明如何聆听小部件中的 DOM dijit 事件将不胜感激。
回答后更新代码:
我稍微修改了代码,如果下一个人觉得有用的话:
on(this.submitButton, 'click', lang.hitch(this, 'execute'));
其中 execute 与之前列出的函数相同,但为了使这一行更简洁。
【问题讨论】:
标签: dom widget dojo event-listener