EmberJS取消(回滚)对象与HasMany [英] EmberJS cancel (rollback) object with HasMany
问题描述
假设我有一个ParentObject,其中有有许多项目。我想在我的添加路线中实现我的取消功能,该路线将回滚所有内容。
简而言之,我有:
父对象 IsNew 和 IsDirty
可能...
项目[]也将是 IsNew 和 IsDirty
所以基本上,我只想杀死我的NewController中的那些...
这里出现错误的代码:
$ $ $ $ $ $ $ $ $ $ $;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
this.get(model)。rollback();
//一些重定向的东西
像它看起来一样简单崩溃...
这是崩溃的控制台输出
未捕获的错误:尝试处理&AppeParentObject上的事件`didSetProperty:ember572:fixture-0>而在状态root.deleted.saved。调用了{name:number,oldValue:undefined,originalValue:undefined,value:undefined}。
如果有人能弄清楚什么可能是错误的,并解释我做错了什么,会很漂亮赞赏!
编辑**
玩过交易,清除关系,没有成功...
我刚遇到这个。对我来说,这是发生的,因为我在执行回滚时有观察员在操作。我不得不通过添加一个检查功能来检查model.isDeleted来防止它们的触发。如果不是,我让它通过,否则阻止它。这似乎为我解决了。
let's say I have a ParentObject that hasMany Items. I want to implement my Cancel feature in my Add route that will rollback everything.
In a nutshell, I have :
ParentObject that IsNew and IsDirty
and potentially...
Items[] that will also be IsNew and IsDirty
So basically, I simply want to kill those within my NewController...
Here come the faulty code :
this.get("items").forEach(function(item)
{
item.deleteRecord();
});
this.get("model").rollback();
// Some redirection stuff
As simple as it may looks, it crashes...
Here's the console output for the crash
Uncaught Error: Attempted to handle event `didSetProperty` on <App.ParentObject:ember572:fixture-0> while in state root.deleted.saved. Called with {name: number, oldValue: undefined, originalValue: undefined, value: undefined}.
If someone could figure out what may be faulty and explain what I'm doing wrong, would be pretty appreciated !
EDIT **
I played around with transaction and clearing the relationships with no success...
I JUST ran into this. For me it was happening because I had observers in operation when I was performing the rollback. I had to prevent them from firing by adding in a check in the function to check for "model.isDeleted". If it wasn't, I let it through, otherwise prevent it. That seemed to solve it for me.
这篇关于EmberJS取消(回滚)对象与HasMany的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!