Constructor
new DataModel(dataopt, optionsopt)
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object |
<optional> |
{} | |||||||||||
options |
Object |
<optional> |
{} |
Properties
|
- Source:
Examples
this.model = new DataModel({ id: 42, something: 'different' })
this.model.get('id') // returns 42
this.model.get('something') // returns 'different'
this.model.get('bogus', 'default') // returns 'default'
class ExampleModel extends DataModel {
get url() { return '/api/example' }
}
this.model = new ExampleModel()
this.model.fetch().then(() => { ... }).catch(err => { ... })
Members
_data :Object.<string, *>
Type:
- Object.<string, *>
- Source:
collection :DataCollection|null
Type:
- DataCollection | null
- Source:
Methods
cleanup()
See DataObject.cleanup for details.
- Source:
delete() → {Promise}
Calls the DELETE method on the service resource
- Source:
Returns:
- Type
- Promise
equals(obj)
Parameters:
Name | Type | Description |
---|---|---|
obj |
* | the value to compare to `this` or `this.get('id')` |
- Source:
get(dataField, defaultValueopt) → {*}
Find a value held within this DataModel.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dataField |
string | |||
defaultValue |
* |
<optional> |
null | a value to return if the field value is `undefined`, `null`, or the empty string |
- Source:
Returns:
may be native types or, if mapped by options.fieldDataObjects, another DataObject
- Type
- *
getFirst(…dataFields) → {*}
Return the first value that this `DataModel.has` or 'undefined' if none are found
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dataFields |
Array.<string> |
<repeatable> |
- Source:
Returns:
may be undefined, native types, or (if mapped by options.fieldDataObjects) another DataObject
- Type
- *
has(dataField) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
dataField |
string |
- Source:
Returns:
true if this model contains a field with the name of `dataField`
- Type
- boolean
increment(dataField, amountopt) → {*}
Add a value to a field, creating the value if necessary
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dataField |
string | |||
amount |
int |
<optional> |
1 |
- Source:
Returns:
the new value of the field
- Type
- *
reset(dataopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object |
<optional> |
{} |
- Source:
set(dataField, value)
Set a key/value pair
Parameters:
Name | Type | Description |
---|---|---|
dataField |
string | |
value |
* | the new value of the field |
- Source:
setBatch()
Set a group of values. The 'values' parameter should be an object that works in for(key in values) loops like a dictionary: {}
If a key is in options.fieldDataObjects then the value will be used to contruct a DataObject and that will be the saved value.
- Source:
stringify() → {string}
- Source:
Returns:
The model data as a JSON-formatted string
- Type
- string