DS.Model.eachAttribute()

eachAttribute (callback, binding) static

Defined in addon/-private/system/model/attr.js:121

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):

function(name, meta);
  • name the name of the current property in the iteration
  • meta 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

import DS from 'ember-data';

var Person = DS.Model.extend({
  firstName: attr('string'),
  lastName: attr('string'),
  birthday: attr('date')
});

Person.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"}

Parameters:

callback Function
The callback to execute
binding [Object]
the value to which the callback's `this` should be bound
doc_EmberJs
2016-11-30 16:50:16
Comments
Leave a Comment

Please login to continue.