Ember model lifecycle, and reverting to original state

懵懂的女人 提交于 2019-12-22 18:29:09

问题


I'm struggling to understand everything about the ember model lifecycle. I have created this jsfiddle to illustrate my problem. When clicking on one of the entries in the list, editing a value, and clicking the versions link to go back to the list, I get the following error:

Uncaught Error: Attempted to handle event loadedData on while in state rootState.loaded.updated.uncommitted. Called with {}

What is causing this? I get that the object state is now dirty, but how can I force a refresh of all objects when the list is opened?

Also, any suggestions on how to discard all changes to the properties if the form is not saved? I was thinking about cloning the object, using that clone in the edit form, and merging that with the original when saving. Not as easy as I first imagined.

Using latest ember and ember-data.


回答1:


After quick discussion with @tchak, a solution could be to override the Version route's exit function, and rollback the current model.

App.VersionRoute = Ember.Route.extend({
  exit: function() {
    var controller = this.controllerFor(this.templateName),
        content = controller.get('content');

    if (content.get('isDirty')) {
      content.get('transaction').rollback(); 
    }
    this._super();
  }
});


来源:https://stackoverflow.com/questions/14154826/ember-model-lifecycle-and-reverting-to-original-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!