Ember模型生命周期,并恢复到原始状态 [英] Ember model lifecycle, and reverting to original state
问题描述
我正努力了解有关余烬模型生命周期的所有信息。我创建了此jsfiddle 来说明我的问题。单击列表中的一项,编辑值,然后单击版本链接以返回到列表时,出现以下错误:
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:
未捕获错误:处于状态rootState.loaded.updated.uncommitted时,尝试处理事件
loadedData
。调用{}
这是什么原因?我知道对象状态现在很脏,但是打开列表时如何强制刷新所有对象?
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.
推荐答案
与@tchak进行快速讨论之后,一个解决方案可能是覆盖Version路由的退出功能,并回滚当前模型。
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();
}
});
这篇关于Ember模型生命周期,并恢复到原始状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!