peirix
peirix

Reputation: 37751

get all widgets inside an element

From the dojo documents on dijit.registry, I see the forEach method accepts a last parameter thisObject. But it doesn't way what that object is. Is it a dijit widget or a dojo object?

I want to destroy all widgets inside an element (that will be replaced by AJAX) so they can be parsed again without conflicting id's.

dijit.registry.forEach(function(w) {
    w.destroyRecursive();
}, dojo.byId("ajaxElement"));

But this destroys ALL widgets on the page...

Upvotes: 7

Views: 4392

Answers (1)

Fu Cheng
Fu Cheng

Reputation: 3395

The thisObject is the scope object to invoke the function passed in as the first parameter of forEach.

A couple of solutions you can use in this case:

1) Use dijit.findWidgets to find all the dijits in a DOM node and destroy them one by one. dijit.findWidgets returns array of widgets which takes domnode as a parameter 2) dojo.parser.parse returns an array of all the dijits that it creates, store that array and destroy the dijits before you call dijit.parser.parse again.

3) Use dijit.registry.filter to filter out the dijits you want to keep.

Upvotes: 4

Related Questions