I have a model created from a JSON object that has many properties related to the user interface (settings panel). I would like to allow the user to update their settings, but I also need a way to revert their changes to the model after making changes to the user interface.
I see many examples using Ember-Data, but we do not use this; I also don't see any obvious patterns / methods in Ember docs. Is there a commonly used pattern to achieve rollback on models without Ember-Data?
, . Ember, (, Ember-Data). , oldProperties newProperties. newProperties. , oldProperties .
oldProperties
newProperties
, Ember . , .
-, , - , , .
listEditController.set('clonedModelContent', Ember.copy(modelContent));
:
close: function () { Ember.setProperties(@get('model'), @get('clonedModelContent')); // navigate somewhere else }
, , . , , , , .
, .
I like to use the rollbackAttributes () method for the model.
import Ember from 'ember'; export default Ember.Component.extend({ actions: { cancelEdit: function() { var model = this.get('objectBeingEdited'); model.rollbackAttributes(); this.toggleProperty('isEditing'); } } });