Dojo和取消注册小部件 [英] Dojo and unregistering widgets
问题描述
尝试使用id = myButton注册窗口小部件,但该ID已经注册
每当我尝试加载dojo内容两次(意味着我通过jQuery.Load加载HTML内容到容器div)。有没有办法在dojo中注销已注册的小部件?我看过一些例子,但是我并没有真正让他们工作。
我的按钮:
< button dojoType =dijit.form.Buttonid =myButton>按钮< / button>
如果您要注销特定的小部件,可以使用他们的 destroy()
或 destroyRecursive()
方法。第二个破坏你正在摧毁的任何小部件(即在表单窗口小部件上调用destroyRecursive也会破坏所有的窗体组件)。
在你的情况下,这听起来好像是在 jQuery.load
-
var widgets = dijit.findWidgets(< containerDiv>);
dojo.forEach(widgets,function(w){
w.destroyRecursive(true);
});
上述代码将注销< containerDiv> $中的所有小部件c $ c>,和保留其关联的DOM节点。要破坏DOM节点,请将
false
传递给 destroyRecursive
。
参考:
http ://dojotoolkit.org/api/1.3/dijit/_Widget/destroyRecursive
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
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.
My button:
<button dojoType="dijit.form.Button" id="myButton">button</button>
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).
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);
});
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.
Reference:
http://dojotoolkit.org/api/1.3/dijit/_Widget/destroyRecursive
这篇关于Dojo和取消注册小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!