Function
eachAttribute (callback, binding) public
Module:
@ember-data/model
Defined in ../model/addon/-private/model.js:1965
- callback
- Function
- The callback to execute
- binding
- Object
- the value to which the callback's `this` should be bound
Iterates through the attributes of the model, calling the passed function on each attribute.
The callback method you provide should have the following signature (all parameters are optional):
1 |
function(name, meta); |
name
the name of the current property in the iterationmeta
the meta object for the attribute property in the iteration
Note that in addition to a callback, you can also pass an optional target
object that will be set as this
on the context.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import Model, { attr } from '@ember-data/model'; class PersonModel extends Model { @attr('string') firstName; @attr('string') lastName; @attr('date') birthday; } PersonModel.eachAttribute(function(name, meta) { console.log(name, meta); }); // prints: // firstName {type: "string", isAttribute: true, options: Object, parentType: function, name: "firstName"} // lastName {type: "string", isAttribute: true, options: Object, parentType: function, name: "lastName"} // birthday {type: "date", isAttribute: true, options: Object, parentType: function, name: "birthday"} |