views:

97

answers:

1

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...

A: 

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.

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.

Alex Cheng