class AFrame.CollectionArray class extends AFrame.CollectionHash
An array collection. Unlike the CollectionHash, the CollectionArray can be accessed via either a key or an index. When accessed via a key, the item's CID will be used. If an item has a cid field when inserted, this cid will be used, otherwise a cid will be assigned.
This raises the same events as AFrame.CollectionHash, but every event will have one additional parameter, index.
Create the array
var collection = AFrame.CollectionArray.create();
// First item is inserted with a cid, inserted at the end of the array.
var aframeCID = collection.insert( { cid: 'cid1',
name: 'AFrame Foundary',
city: 'London',
country: 'United Kingdom'
} );
// aframeCID variable will be 'cid1'
// inserts google at the head of the list.
var googleCID = collection.insert( { name: 'Google',
city: 'Santa Clara',
country: 'United States'
}, 0 );
// googleCID will be assigned by the system
// microsoft inserted at the end of the list.
var microsoftCID = collection.insert( { name: 'Microsoft',
city: 'Redmond',
country: 'United States'
}, -1 );
// microsoftCID will be assigned by the system
// Getting an item via index. This will return google item.
var item = collection.get( 0 );
// item will be the google item
// Getting an item via negative index. This will return microsoft item.
var item = collection.get( -1 );
// item will be the microsoft item
// Getting an item via CID. This will return the aframe item.
item = collection.get( aframeCID );
var googleItem = collection.remove( googleCID );
// googleItem will be the google item that was inserted
var aframeItem = collection.remove( 0 );
// aframeItem will be the aframe item since the google item was first but is now removed
Uses…
Constructor
| Constructor | Parameters | Returns |
|---|---|---|
AFrame.CollectionArray(
)
|
Methods
| Methods | Returns | Description |
|---|---|---|
clear(
)
|
void
|
↑
Clear the array
|
get(
index
)
|
variant
|
↑
Get an item from the array.
Parameters:
Returns: |
getArray(
)
|
array
|
↑
Get an array representation of the CollectionArray
Returns:
|
getCID(
index
)
|
void
private
|
↑
Given an index or cid, get the cid. Parameters:
|
getCount(
)
|
number
|
↑
Get the current count of items
Returns:
|
getEventObject(
)
|
void
private
|
↑ |
getIndex(
index
)
|
void
private
|
↑
Given an index or cid, get the index. Parameters:
|
insert(
item, index
)
|
id
|
↑
Insert an item into the array.
Parameters:
Returns: |
remove(
index
)
|
void
|
↑
Remove an item from the array
Parameters:
|
Methods inherited from AFrame.ObservablesMixin
| Methods | Notes |
|---|---|
bindEvent
|
↑ |
bindTo
|
↑ |
getEventObject
|
↑ |
isEventTriggered
|
↑ |
proxyEvents
|
↑ |
setEventData
|
↑ |
triggerEvent
|
↑ |
unbindAll
|
↑ |
unbindEvent
|
↑ |
unbindTo
|
↑ |
unbindToAll
|
↑ |
Methods inherited from AFrame.ArrayCommonFuncsMixin
| Methods | Notes |
|---|---|
addCreate
|
↑ |
AFrame.Class.walkChain
|
↑ |
Class
|
↑ |
getActualIndex
|
↑ |
getActualInsertIndex
|
↑ |
getCount
|
↑ |
Methods inherited from AFrame.AObject
| Methods | Notes |
|---|---|
addChild
|
↑ |
bindEvents
|
↑ |
getCID
|
↑ |
getConfig
|
↑ |
init
|
↑ |
removeChild
|
↑ |
teardown
|
↑ |
triggerProxy
|
↑ |
Methods inherited from AFrame.EnumerableMixin
| Methods | Notes |
|---|---|
filter
|
↑ |
getCount
|
↑ |
search
|
↑ |
Methods inherited from AFrame.CollectionHash
| Methods | Notes |
|---|---|
clear
|
↑ |
forEach
|
↑ |
get
|
↑ |
insert
|
↑ |
remove
|
↑ |
Events inherited from AFrame.AObject
| Events | Notes |
|---|---|
onInit
|
↑ |
onTeardown
|
↑ |
Events inherited from AFrame.CollectionHash
| Events | Notes |
|---|---|
onBeforeInsert
|
↑ |
onBeforeRemove
|
↑ |
onInsert
|
↑ |
onRemove
|
↑ |
Configuration Attributes inherited from AFrame.AObject
| Attributes | Notes |
|---|---|
{cid} cid
|
↑ |