我有一个dojo小部件,它使用了一个自定义库代码,在其模板中有一个像这样的链接。有没有办法断开由dojoAttachEvent添加的事件
<a href="#" dojoAttachEvent="onclick:_goBack" dojoAttachPoint="backButton">Go Back</a>
我需要找到一种方法从我的小部件断开此事件。我知道一个事件是如何被断开的唯一方法是,使用
dojo.disconnect(handle)
我可以用这个,如果我有事件中使用道场连接,连接()返回我把手。 但 dojoAttachEvent我没有事件句柄,因此无法断开它。
注意: 更改这个html不是我的选择,因为这是我使用的外部库。
此外,我没有找到解决方案来断开所有事件。
CODE:
otherWidget.js:
dojo.provide("otherWidget");
dojo.declare("otherWidget", [], {
templateString : dojo.cache("otherWidget","templates/otherWidget.html"),
_goBack: function(){
this.destroyWidgetAndRedirect();
},
destroyWidgetAndRedirect: function(){
//Code to destory and redirect.
},
});
otherWidget.html:
<div>
<a href="#" dojoAttachEvent="onclick:_goBack" dojoAttachPoint="backButton">Go Back</a>
<!-- Other Widget related code -->
...
</div>
myWidget.js:
dojo.provide("myWidget");
dojo.require("otherWidget");
dojo.declare("myWidget", [], {
templateString : dojo.cache("myWidget","templates/myWidget.html"),
this.otherWidget = new otherWidget({}, dojo.byId('otherWidgetContainer'));
});
myWidget.html:
<div>
<div id="otherWidgetContainer"></div>
<!-- My Widget related code -->
...
</div>
任何想法.. 感谢。
究竟是什么你想达到什么目的?阻止默认的onClick事件执行?如果是这种情况,我认为你应该通过dojo/method使用_goBack扩展点。它将把事件作为第一个参数,并且您可以在重写代码的开始处使用evt.preventDefault()...请参阅http://dojotoolkit.org/reference-guide/quickstart/writingWidgets.html#creating-扩展点 – Philippe
嗨菲利普,感谢您的回复。是的,我的最终动机是防止默认的onClick事件。不知道我是否理解正确,但在扩展点示例中,我将不得不修改我的库代码,以便它调用onClick?此外,即使我在onClick函数中添加evt.preventDefault,_goBack和_onClick仍然会在onClick之前执行(如链接中的示例所示)。基本上我的查询是现在我在哪里写覆盖代码 –