Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dojo

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

like image 619
screenm0nkey Avatar asked Oct 25 '11 08:10

screenm0nkey


1 Answers

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
}
like image 199
hugomg Avatar answered Oct 28 '22 15:10

hugomg