获取“错误:断言失败:在被破坏的对象上调用集合”当尝试回滚删除 [英] Getting "Error: Assertion Failed: calling set on destroyed object" when trying to rollback a deletion

查看:199
本文介绍了获取“错误:断言失败:在被破坏的对象上调用集合”当尝试回滚删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从服务器发回错误时,我正在研究如何在ember中显示正确的删除错误信息。我看了这个话题,并按照其建议:
Ember Data delete failed ,如何回滚



我的代码就是这样,我返回一个400,我的捕捉到的日志,但没有任何反应,当我暂停它调试器虽然并尝试回滚,我得到错误:断言失败:调用设置在已销毁的对象上



所以A)我无法回滚B)错误正常吃掉。 / p>

这是我的代码

  visitor.destroyRecord()。then function(){
console.log('SUCCESS');
})。catch(function(response){
console.log('failed to remove',response);
visitor.rollback();
});

如果相关,我的模型确实有多个关系。我究竟做错了什么? Ember数据版本是1.0.0.8 beta(前几天从前几天发布)。



提前感谢





我现在发现,根据ember检查器,该记录实际上正在恢复缓存内,但是对象将不再出现在游客的呈现中。我需要一些方法来强制重新载入模板...

解决方案

在回滚后尝试重新加载模型。它将从服务器重新加载,但这是我可以找到的唯一方法。

  visitor.destroyRecord() (function(){
console.log('SUCCESS');
})。catch(function(response){
console.log('failed to remove',response);
visitor.rollback();
visitor.reload()。then(function(vis)
{
console.log('visitor.reload ::'+ JSON.stringify对));
});
});

希望有所帮助。


I am looking into how to show proper deletion error message in ember when there is an error coming back from the server. I looked at this topic and followed its suggestion: Ember Data delete fails, how to rollback

My code is just like it, I return a 400 and my catch fires and logs, but nothing happens, when I pause it in the debugger though and try to rollback, I get Error: Assertion Failed: calling set on destroyed object

So A) I cannot rollback B) the error is eaten normally.

Here is my code

visitor.destroyRecord().then(function() {
                    console.log('SUCCESS');
                }).catch(function(response) {
                    console.log('failed to remove', response);
                    visitor.rollback();                        
                });

In case it's relevant, my model does have multiple relationships. What am I doing wrong? Ember-data version is 1.0.0.8 beta (previous one from the release a few days ago).

Thanks in advance.

EDIT

I discovered now that the record actually is restored currently inside the cache according to ember inspector, but the object will not reappear in the rendering of the visitors. I need some way to force it to reload into the template...

解决方案

Try reloading the model after the rollback. It will reload from the server but it was the only way around this that I could find.

visitor.destroyRecord().then(function() {
                console.log('SUCCESS');
            }).catch(function(response) {
                console.log('failed to remove', response);
                visitor.rollback();
                visitor.reload().then(function(vis)
                {
                    console.log('visitor.reload :: ' + JSON.stringify(vis));
                });
            });

Hope that helps.

这篇关于获取“错误:断言失败:在被破坏的对象上调用集合”当尝试回滚删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆