Dojo 和注销小部件 [英] Dojo and unregistering widgets
问题描述
我是 Dojo 工具包的新手.我收到了错误
I am new to the Dojo Toolkit. I'm getting the error
Tried to register widget with id=myButton but that id is already registered
每当我尝试加载 dojo 内容两次(这意味着我通过 jQuery.Load 将 HTML 内容加载到容器 div 中).有没有办法在 dojo 中取消注册已经注册的小部件?我看过一些例子,但我并没有真正让它们发挥作用.
whenever I try to load dojo content twice (meaning I load HTML content through jQuery.Load into a container div). Is there a way of unregistering already registered widgets in dojo? I've seen some examples, but I don't really get them working.
我的按钮:
<button dojoType="dijit.form.Button" id="myButton">button</button>
推荐答案
如果你想取消注册特定的小部件,你可以使用它们的 destroy()
或 destroyRecursive()代码>方法.第二个销毁您正在销毁的那个内部的任何小部件(即在表单小部件上调用destroyRecursive也将销毁所有表单组件).
If you're looking to unregister specific widgets, you can use their destroy()
or destroyRecursive()
methods. The second one destroys any widgets inside the one you are destroying (i.e. calling destroyRecursive on a form widget will also destroy all the form components).
在您的情况下,听起来您最好的选择是在 jQuery.load
-
In your case, it sounds like your best bet would be to do this before jQuery.load
-
var widgets = dijit.findWidgets(<containerDiv>);
dojo.forEach(widgets, function(w) {
w.destroyRecursive(true);
});
以上代码将注销<containerDiv>
中的所有小部件,和保留它们关联的DOM节点.要销毁 DOM 节点,请将 false
传递给 destroyRecursive
.
The above code will unregister all widgets in <containerDiv>
, and preserve their associated DOM Nodes. To destroy the DOM nodes, pass false
to destroyRecursive
instead.
参考:
http://dojotoolkit.org/api/1.3/dijit/_Widget/destroyRecursive
这篇关于Dojo 和注销小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!