new tart.Collection(initialList, activeItem){tart.Collection}
Constructor method
Name | Type | Description |
---|---|---|
initialList |
tart.JSON |
optional
Default list items in JSON format. |
activeItem |
number |
optional
Default selected item index. |
Returns:
Type | Description |
---|---|
tart.Collection | A list object. |
Extends
- goog.pubsub.PubSub
Methods
-
addItem(key, value){boolean}
-
Adds a new key-value pair to the collection.
Name Type Description key
number | string Key for the pair.
value
* Value for the pair.
Returns:
Type Description boolean Returns true if the add operation was successful. -
getActiveItem(){tart.JSON}
-
Returns active item as JSON object.
Returns:
Type Description tart.JSON returns the active key-value pair from the collection. -
getActiveItemIndex(){number}
-
Returns active item's index.
Returns:
Type Description number returns the active index in the collection. -
getActiveItemKey(){string|number}
-
Returns active item's key.
Returns:
Type Description string | number returns the active key from the collection. -
getActiveItemValue(){*}
-
Returns active item's value.
Returns:
Type Description * returns the active value from the collection. -
getAll(){Array}
-
Dumps all items in an array.
Returns:
Type Description Array returns all pairs as an array. -
getByIndex(index){tart.JSON|boolean|undefined}
-
Returns item by given index.
Name Type Description index
number Index to search in the collection.
Returns:
Type Description tart.JSON | boolean | undefined returns the key-value pair given an index. -
getByKey(key){tart.JSON}
-
Returns item by given key. If not found, returns boolean false.
Name Type Description key
string | number key to search for.
Returns:
Type Description tart.JSON returns the key-value pair given a specific key. -
getByValue(val){tart.JSON}
-
Returns item by given value. If not found, returns boolean false.
Name Type Description val
string | number value to search for.
Returns:
Type Description tart.JSON returns the key-value pair given a specific value. -
getItems(){tart.JSON}
-
Returns all items in a kvp format.
Returns:
Type Description tart.JSON obj returns an object that contains keys as its keys and values as its values. -
getKeys(){Array}
-
Returns all keys in an array.
Returns:
Type Description Array returns all keys in an array. -
getValues(){Array}
-
Returns all values in an array.
Returns:
Type Description Array returns all values in an array. -
removeByIndex(index){number|boolean|undefined}
-
Removes an item from collection which given by index and rebuilds the item collection. Returns new activeItemIndex if item successfully removed or FALSE if not.
Name Type Description index
number Index to remove.
Returns:
Type Description number | boolean | undefined Condition of the operation or the active item index. -
removeByKey(key)
-
Removes items by key.
Name Type Description key
string Game items key.
-
setActiveItemIndex(newIndex){boolean}
-
Sets active item index.
Name Type Description newIndex
number index to set as the new active item.
Returns:
Type Description boolean Whether the method was able to set the item.