screenm0nkey
screenm0nkey

Reputation: 18795

Is there a way in Dojo to find all widget descendants in a DOM element?

Is there a way in Dojo to find all widget descendants in a DOM element? I used the example below it will only list the children of the element, in this case any widgets that are children of the document object, but not all the descendants or nested widgets. Hopefully that's clear.

var widgets = dijit.findWidgets(dojo.doc);
dojo.forEach(widgets, function(w) {
    console.log(w);
});

I could just write my own recursive function but I want to make sure I'm not missing out on a Dojo method which already does this.

Many thanks

Upvotes: 6

Views: 6199

Answers (1)

hugomg
hugomg

Reputation: 69934

Hmm, dijit.findWidgets(parentWidget.domNode) ?

Edit Oh, now I nee findWidgets doesn't search recursively.

I checked the dijit.findWidgets source code and all it does is check for nodes with a widgetid attribute that are represented in the dijit registry. The following version uses dojo.query to do this same search recursively:

function findEvenTheNestedWidgets(innitialNode){
    return dojo.query("[widgetid]", innitialNode)
    .map(dijit.byNode)
   .filter(function(wid){ return wid;}) //filter invalid widget ids that yielded undefined
}

Upvotes: 9

Related Questions