class AFrame.DataContainer class extends AFrame.AObject
DataContainers are the basic atom of data within the AFrameJS ecosystem. Used like a hash. They provide functionality allowing concerned parties to be notified when the data mutates. They are the "Model" in Model-View-Controller. DataContainer's make it possible to have multiple Views bound to a particular field update automatically when the underlying data is modified.
Example:
var dataObject = {
firstName: 'Shane',
lastName: 'Tomlinson'
};
var dataContainer = AFrame.DataContainer.create( { data: dataObject } );
dataContainer.bindField( 'firstName', function( notification ) {
alert( 'new name: ' + notification.value );
} );
dataContainer.set( 'firstName', 'Charlotte' );
Uses…
Known subclasses
Methods
| Methods | Returns | Description |
|---|---|---|
AFrame.DataContainer.create(
data
)
|
void
|
↑
Create a DataContainer.
Parameters:
|
bindField(
fieldName, callback, context
)
|
id
|
↑
Bind a callback to a field. Function is called once on initialization as well as any time the field changes. When function is called, it is called with an event.
Parameters:
Returns: |
forEach(
function, context
)
|
void
|
↑
Iterate over each item in the dataContainer. Callback will be called with two parameters, the first the value, the second the key
Parameters:
|
get(
fieldName
)
|
variant
|
↑
Get the value of a field
Parameters:
Returns: |
init(
)
|
void
|
↑
Initialize the data container. |
set(
fieldName, fieldValue
)
|
variant
|
↑
Update a field.
Parameters:
Returns: |
toJSON(
)
|
object
|
↑
Get an object with all fields contained in the DataContainer.
|
unbindField(
id
)
|
void
|
↑
Unbind a field.
Parameters:
|
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
|
↑ |
checkRequired
|
↑ |
getCID
|
↑ |
getConfig
|
↑ |
init
|
↑ |
removeChild
|
↑ |
teardown
|
↑ |
triggerProxy
|
↑ |
Methods inherited from AFrame.EnumerableMixin
| Methods | Notes |
|---|---|
filter
|
↑ |
getCount
|
↑ |
search
|
↑ |
Events
| Events | Description |
|---|---|
onSet(
event
)
|
↑
Triggered whenever any item on the object is set. Parameters:
|
onSet-fieldName(
event
)
|
↑
Triggered whenever an item on the object is set. This is useful to bind to whenever a particular field is being changed. Parameters:
|
Events inherited from AFrame.AObject
| Events | Notes |
|---|---|
onInit
|
↑ |
onTeardown
|
↑ |
Configuration Attributes
| Attributes | Type | Description |
|---|---|---|
data
|
{object}
|
↑
Initial data
Default value:
{}
|
Configuration Attributes inherited from AFrame.AObject
| Attributes | Notes |
|---|---|
{cid} cid
|
↑ |