dijit/WidgetSet (version 1.10)

Summary

A set of widgets indexed by id. Deprecated, will be removed in 2.0.

Usage

var foo = new WidgetSet();
dijit/WidgetSet

See the dijit/WidgetSet reference documentation for more information.

Examples

Example 1

Create a small list of widgets:

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    var ws = new WidgetSet();
    ws.add(registry.byId("one"));
    ws.add(registry.byId("two"));
    // destroy both:
    ws.forEach(function(w){ w.destroy(); });
});

Method Summary

  • add(widget) Add a widget to this list.
  • byClass(cls) Reduce this widgetset to a new WidgetSet of a particular declaredClass
  • byId(id) Find a widget in this list by it's id.
  • every(func,thisObj) A synthetic clone of array.every acting explicitly on this WidgetSet
  • filter(filter,thisObj) Filter down this WidgetSet to a smaller new WidgetSet Works the same as array.filter and NodeList.filter
  • forEach(func,thisObj) Call specified function for each widget in this set.
  • map(func,thisObj) Create a new Array from this WidgetSet, following the same rules as array.map
  • remove(id) Remove a widget from this WidgetSet.
  • some(func,thisObj) A synthetic clone of array.some acting explicitly on this WidgetSet
  • toArray() Convert this WidgetSet into a true Array

Methods

add(widget)
Defined by dijit/WidgetSet

Add a widget to this list. If a duplicate ID is detected, a error is thrown.

Parameter Type Description
widget dijit/_WidgetBase

Any dijit/_WidgetBase subclass.

byClass(cls)
Defined by dijit/WidgetSet

Reduce this widgetset to a new WidgetSet of a particular declaredClass

Parameter Type Description
cls String

The Class to scan for. Full dot-notated string.

Returns:instance

Examples

Example 1

Find all dijit.TitlePanes in a page:

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    registry.byClass("dijit.TitlePane").forEach(function(tp){ tp.close(); });
});
byId(id)
Defined by dijit/WidgetSet

Find a widget in this list by it's id.

Parameter Type Description
id String
Returns:undefined

Examples

Example 1

Test if an id is in a particular WidgetSet

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    var ws = new WidgetSet();
    ws.add(registry.byId("bar"));
    var t = ws.byId("bar") // returns a widget
    var x = ws.byId("foo"); // returns undefined
});
every(func,thisObj)
Defined by dijit/WidgetSet

A synthetic clone of array.every acting explicitly on this WidgetSet

Parameter Type Description
func Function

A callback function run for every widget in this list. Exits loop when the first false return is encountered.

thisObj Object
Optional

Optional scope parameter to use for the callback

Returns:boolean
filter(filter,thisObj)
Defined by dijit/WidgetSet

Filter down this WidgetSet to a smaller new WidgetSet Works the same as array.filter and NodeList.filter

Parameter Type Description
filter Function

Callback function to test truthiness. Is passed the widget reference and the pseudo-index in the object.

thisObj Object
Optional

Option scope to use for the filter function.

Returns:instance

Examples

Example 1

Arbitrary: select the odd widgets in this list

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    registry.filter(function(w, i){
        return i % 2 == 0;
    }).forEach(function(w){ /* odd ones */ });
});
forEach(func,thisObj)
Defined by dijit/WidgetSet

Call specified function for each widget in this set.

Parameter Type Description
func Function

A callback function to run for each item. Is passed the widget, the index in the iteration, and the full hash, similar to array.forEach.

thisObj Object
Optional

An optional scope parameter

Returns:any | function

Returns self, in order to allow for further chaining.

Examples

Example 1

Using the default dijit.registry instance:

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    registry.forEach(function(widget){
        console.log(widget.declaredClass);
    });
});
map(func,thisObj)
Defined by dijit/WidgetSet

Create a new Array from this WidgetSet, following the same rules as array.map

Parameter Type Description
func Function
thisObj Object
Optional
Returns:any | undefined

A new array of the returned values.

Examples

Example 1

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    var nodes = registry.map(function(w){ return w.domNode; });
});
remove(id)
Defined by dijit/WidgetSet

Remove a widget from this WidgetSet. Does not destroy the widget; simply removes the reference.

Parameter Type Description
id String
some(func,thisObj)
Defined by dijit/WidgetSet

A synthetic clone of array.some acting explicitly on this WidgetSet

Parameter Type Description
func Function

A callback function run for every widget in this list. Exits loop when the first true return is encountered.

thisObj Object
Optional

Optional scope parameter to use for the callback

Returns:boolean
toArray()
Defined by dijit/WidgetSet

Convert this WidgetSet into a true Array

Returns:Array

Examples

Example 1

Work with the widget .domNodes in a real Array

require(["dijit/WidgetSet", "dijit/registry"],
    function(WidgetSet, registry){
    array.map(registry.toArray(), function(w){ return w.domNode; });
});
Error in the documentation? Can’t find what you are looking for? Let us know!