3.0 beta 2

AX.Collection

ActiveWidgets collections work as an ordered set of key/value pairs. You can put and retrieve elements either by key (string) or an index (number).

var items = new AX.Collection(['abc', 'def', 'xyz']);

items.get(0); // returns 'abc'

Methods

add( value )

Adds an element into the collection (as the last element).

items.add(123);

Parameters

  • value - Any. The element to add into the collection.

Returns

  • this (chainable)

count()

Returns the number of elements in the collection.

var n = items.count();

Returns

  • Number. The number of elements.

each( fn )

Calls the function for each element of the collection.

items.each(function(value, index, key){
    // do something
});

Parameters

  • fn - Function. The function to call. If the function returns something other than undefined, the iteration stops and the result is returned.

Returns

  • Any. The function result if any.

get( index | key )

Returns the collection element by index or key.

var item = items.get(i);

Parameters

  • index | key - Number|String. The element's index (number) or key (string).

Returns

  • Any. The collection element.

remove( index )

Removes the element at the given index from the collection.

items.remove(i);

Parameters

  • index - Number. The element's index.

Returns

  • this (chainable)

set( index | key, value )

Puts the element into the collection. if an element with a given key already exists, it will be replaced with a new value.

items.set(key, value);

Parameters

  • index | key - Number|String. The element's index (number) or key (string).
  • value - Any. The element to put into the collection.

Returns

  • this (chainable)