Sunday, May 8, 2011

Dijit.ByType

I couldn't find anything like this in the dijit library so here's a way to get a dijit with a certain declaredClass:

        dijit.byType = function (type, scope) {
            var scope = scope || dojo.body();
            var result = [];
            var f = function (scope) {
                dojo.forEach(dijit.findWidgets(scope), function (w) {
                    if (w.declaredClass === type) result.push(w);
                    f(w.domNode);
                });
            };
            f(scope);
            return result;
        };

Usage:

dijit.byType("dijit.Tree", dojo.body());

No comments:

Post a Comment