Discard model changes without Ember-Data

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?

+3
source share
3 answers

, . Ember, (, Ember-Data). , oldProperties newProperties. newProperties. , oldProperties .

, Ember . , .

+2

-, , - , , .

listEditController.set('clonedModelContent', Ember.copy(modelContent));

:

close: function () {
  Ember.setProperties(@get('model'), @get('clonedModelContent'));
  // navigate somewhere else
}

, , . , , , , .

, .

0

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');
        }
    }
});
0
source

All Articles