如果我调用 destroyRecord 并且它在服务器上失败,它也会从本地存储和 UI 中消失。如果删除失败,我需要以某种方式“回滚”。我尝试过这样的事情。
item.destroyRecord().then(function () {
Notify.success("item removed");
}).catch(function (response) {
//NEED TO ROLLBACK HERE - ANY IDEAS?
Notify.error('Failed to remove!');
});
首先,关系回滚在 ember 数据中并不完全有效,其次,较新版本的 ember 数据可以更好地处理这个问题(ember 数据 1.0 beta 7+)。为此,记录有一个回滚方法,它仍处于测试阶段,但它基本上可以满足您的需求。
item.destroyRecord().then(function () {
Notify.success("item removed");
}).catch(function (response) {
item.rollback();
Notify.error('Failed to remove!');
});
NOTE:在较新版本的 Ember 中,item.rollback()
不再起作用,而是使用item.rollbackAttributes()
正如马塞洛的评论中提到的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)