Dojo-在小部件中侦听domdijit/form/button单击事件

Dojo-在小部件中侦听domdijit/form/button单击事件,dom,widget,dojo,event-listener,Dom,Widget,Dojo,Event Listener,我正在向一个ERSI地图查看器项目添加小部件,可以在这里找到 因此,我制作了一个带有dijit/form/button的查询小部件,并希望实现一个dojo/on事件侦听器来侦听它的click事件 该按钮在html标记中声明为: <button data-dojo-type="dijit.form.Button" id="searchButton" type="button">Submit</button> 我收到一个TypeError:_526为空。这个错误似乎可以忽

我正在向一个ERSI地图查看器项目添加小部件,可以在这里找到

因此,我制作了一个带有dijit/form/button的查询小部件,并希望实现一个dojo/on事件侦听器来侦听它的click事件

该按钮在html标记中声明为:

<button data-dojo-type="dijit.form.Button" id="searchButton" type="button">Submit</button> 
我收到一个TypeError:_526为空。这个错误似乎可以忽略不计,因为我知道我做得不对。除了上面的代码外,我已经尝试了几十种其他代码,但都没有效果

我找到的所有示例都没有显示如何执行这个特定的应用程序

我是dojo的新手,我只在这个项目上工作,直到我能解决其他同事遇到的一些问题,但如果有人能给我展示一个示例或链接到一个示例,演示如何在小部件中侦听DOM dijit事件,我将不胜感激

回答后更新代码:

如果下一个人觉得有用,我会稍微更改代码:

on(this.submitButton, 'click', lang.hitch(this, 'execute'));

其中execute与前面列出的函数相同,只是为了使此行更简洁。

我假设您的查询小部件是一个模板小部件,并且还混合了WidgetsInTemplateMixin

您发布的html位于小部件模板中。您最好的选择是不使用id。通过使用id,您将只能在页面上拥有其中一个小部件。对于您的用例来说,这可能还可以,但这不是一个好的实践。相反,请使用
数据dojo附着点

<div>
    ... MORE HTML...
    <button data-dojo-type="dijit.form.Button" 
        data-dojo-attach-point="submitButton" type="button">Submit</button>
</div>

因为按钮本身是一个小部件,所以不需要dojo/on来截获click事件

假设您将“dijit/registry”放在小部件的依赖项列表中,请尝试:

registry.byId("searchButton").on("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);
});
你出错的原因是因为当你这样做的时候

<button data-dojo-type="dijit.form.Button" id="searchButton" type="button">Submit</button>

如果查看,您将看到按钮domNode根本没有id。如果现在在Firebug或浏览器控制台中查看该按钮的html,您将注意到domNode具有属性“widgetid=btn2”,而不是“id=btn2”

嗨,谢谢你的评论。这是我发帖时的错误。代码实际上使用了您突出显示的正确html代码。更新的问题反映了这一点。您是正确的,它是一个模板小部件,在WidgetsInTemplateMixin中进行混合。你的回答恰到好处,效果很好。也谢谢你的解释。给我+1。。。我没有意识到html实际上在小部件模板中。我留下我的答案,因为它可能会添加一些信息。。。
registry.byId("searchButton").on("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);
});
<button data-dojo-type="dijit.form.Button" id="searchButton" type="button">Submit</button>
registry.byId("searchButton").domNode