class AFrame.CollectionHash class extends AFrame.AObject
A hash collection. Items stored in the hash can be accessed/removed by a key. The item's key is first searched for on the item's cid field, if the item has no cid field, a cid will be assigned to it. The CID used is returned from the insert function.
CollectionHash is different from a CollectionArray which is accessed by index.
Create the hash
var collection = AFrame.CollectionHash.create();
// First item is inserted with a cid
var cid = collection.insert( { cid: 'cid1',
name: 'AFrame Foundary',
city: 'London',
country: 'United Kingdom'
} );
// cid variable will be 'cid1'
var googleCID = collection.insert( { name: 'Google',
city: 'Santa Clara',
country: 'United States'
} );
// googleCID will be assigned by the system
// Getting an item from the hash.
var item = collection.get( 'cid1' );
// item will be the AFrame Foundary item
var googleItem = collection.remove( googleCID );
// googleItem will be the google item that was inserted
Uses…
Known subclasses
Constructor
| Constructor | Parameters | Returns |
|---|---|---|
AFrame.CollectionHash(
)
|
Methods
| Methods | Returns | Description |
|---|---|---|
clear(
)
|
void
|
↑
Clear the hash
|
forEach(
callback, context
)
|
void
|
↑
Iterate over the collection, calling a function once for each item in the collection.
Parameters:
|
get(
cid
)
|
variant
|
↑
Get an item from the hash.
Parameters:
Returns: |
insert(
item, options
)
|
id
|
↑
Insert an item into the hash. CID is gotten first from the item's cid field. If this doesn't exist, it is then assigned. Items with duplicate cids are not allowed, this will cause a 'duplicate cid' exception to be thrown. If the item being inserted is an Object and does not already have a cid, the item's cid will be placed on the object under the cid field. When onBeforeInsert is triggered, if the event has had preventDefault called, the insert will be cancelled
Parameters:
Returns: |
remove(
item, options
)
|
variant
|
↑
Remove an item from the store.
An Example can be found on JSFiddle Parameters:
Returns: |
Methods inherited from AFrame.ObservablesMixin
| Methods | Notes |
|---|---|
bindEvent
|
↑ |
bindTo
|
↑ |
getEventObject
|
↑ |
isEventTriggered
|
↑ |
proxyEvents
|
↑ |
setEventData
|
↑ |
triggerEvent
|
↑ |
unbindAll
|
↑ |
unbindEvent
|
↑ |
unbindTo
|
↑ |
unbindToAll
|
↑ |
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
|
↑ |
Events
| Events | Description |
|---|---|
onBeforeInsert(
data
)
|
↑
Triggered before insertion happens. If listeners call preventDefault on the event, item will not be inserted Parameters:
|
onBeforeRemove(
data
)
|
↑
Triggered before remove happens. If listeners call preventDefault on the event object, the remove will not happen. Parameters:
|
onInsert(
data
)
|
↑
Triggered after insertion happens. Parameters:
|
onRemove(
data
)
|
↑
Triggered after remove happens. Parameters:
|
Events inherited from AFrame.AObject
| Events | Notes |
|---|---|
onInit
|
↑ |
onTeardown
|
↑ |
Configuration Attributes inherited from AFrame.AObject
| Attributes | Notes |
|---|---|
{cid} cid
|
↑ |