Collection
Extends ICollection, collection.Item.
Basic implementation of an object collection on the map.
Constructor | Fields | Events | Methods
Constructor
Collection([options])
Parameters:
Parameter |
Default value |
Description |
— |
Type: Object Collection options. |
Fields
Name |
Type |
Description |
Event manager. Inherited from IEventEmitter. |
||
Options manager. Inherited from ICustomizable. |
Events
Name |
Description |
A child object was added. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Map reference changed. Data fields:
Inherited from IParentOnMap. |
|
Change to the object options. Inherited from ICustomizable. |
|
The parent object reference changed. Data fields:
Inherited from IChild. |
|
A child object was deleted. Instance of the Event class. Names of fields that are available via the Event.get method:
|
Methods
Name |
Returns |
Description |
Adds an item to the collection. |
||
Calls a handler function for all the items in the collection. |
||
Object[] |
Calls a filter function for all the items in the collection. When the filter returns a non-zero value, the collection item goes in the final array. |
|
Object |
Returns a collection item, or null if the number is outside of the range for the collection's numbers. |
|
getAll() |
Object[] |
Returns an array with all the collection items. |
Returns an iterator for selecting collection items. |
||
Number |
Returns the number of items in the collection. |
|
getMap() |
Returns the map that the collection item belongs to. Inherited from collection.Item. |
|
Returns parent object. Inherited from collection.Item. |
||
Number |
Returns the sequential number of the object in the collection, or -1 if the object was not found. |
|
Function that is called when adding an element to the map. To perform additional actions when adding the object to the map, redefine this function. Inherited from collection.Item. |
||
Function that is called when deleting an element from the map. To perform additional actions when deleting the object from the map, redefine this function. Inherited from collection.Item. |
||
Deletes an item from a collection. |
||
Deletes all the items from a collection. |
||
Sets the parent for the selected item in a collection. Inherited from collection.Item. |
Events details
add
A child object was added. Instance of the Event class. Names of fields that are available via the Event.get method:
- child - Child element that was added.
remove
A child object was deleted. Instance of the Event class. Names of fields that are available via the Event.get method:
- child - Child element that was deleted.
Methods details
add
{Collection} add(child)
Adds an item to the collection.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: collection.Item Element to add. |
* Mandatory parameter/option.
each
{Collection} each(callback[, context])
Calls a handler function for all the items in the collection.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Function Handler function. Receives a collection item as input. If the function returns the value "false," processing stops. |
|
— |
Type: Object Context of the invoked function. |
* Mandatory parameter/option.
filter
{Object[]} filter(filterFunction)
Calls a filter function for all the items in the collection. When the filter returns a non-zero value, the collection item goes in the final array.
Returns an array of items that were selected.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Function Function that works as a filter for the collection's objects. It takes an item from the collection as the first parameter. It should return a boolean value. |
* Mandatory parameter/option.
get
{Object} get(index)
Returns a collection item, or null if the number is outside of the range for the collection's numbers.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Number The sequential number of the item in the collection. |
* Mandatory parameter/option.
getAll
{Object[]} getAll()
Returns an array with all the collection items.
getIterator
{IIterator} getIterator()
Returns an iterator for selecting collection items.
getLength
{Number} getLength()
Returns the number of items in the collection.
indexOf
{Number} indexOf(childToFind)
Returns the sequential number of the object in the collection, or -1 if the object was not found.
Parameters:
Parameter |
Default value |
Description |
— |
Type: Object The required object. |
* Mandatory parameter/option.
remove
{Collection} remove(child)
Deletes an item from a collection.
Returns self-reference.
Parameters:
Parameter |
Default value |
Description |
— |
Type: collection.Item Item to delete. |
* Mandatory parameter/option.
removeAll
{Collection} removeAll()
Deletes all the items from a collection.
Returns self-reference.
Mandatory parameter/option.