DS.Model#changedAttributes()

changedAttributesObject

Defined in addon/-private/system/model/model.js:605

Returns an object, whose keys are changed properties, and value is an [oldProp, newProp] array.

The array represents the diff of the canonical state with the local state of the model. Note: if the model is created locally, the canonical state is empty since the adapter hasn't acknowledged the attributes yet:

Example

app/models/mascot.js
import DS from 'ember-data';

export default DS.Model.extend({
  name: attr('string'),
  isAdmin: attr('boolean', {
    defaultValue: false
  })
});
var mascot = store.createRecord('mascot');

mascot.changedAttributes(); // {}

mascot.set('name', 'Tomster');
mascot.changedAttributes(); // { name: [undefined, 'Tomster'] }

mascot.set('isAdmin', true);
mascot.changedAttributes(); // { isAdmin: [undefined, true], name: [undefined, 'Tomster'] }

mascot.save().then(function() {
  mascot.changedAttributes(); // {}

  mascot.set('isAdmin', false);
  mascot.changedAttributes(); // { isAdmin: [true, false] }
});

Returns:

Object
an object, whose keys are changed properties, and value is an [oldProp, newProp] array.
doc_EmberJs
2016-11-30 16:50:05
Comments
Leave a Comment

Please login to continue.