我有一个工作流程,我必须删除一条记录,但是如果后端抛出任何错误,那么我会显示一个错误对话框,上面有一个关闭按钮。用户可以关闭该错误对话框并返回主屏幕,在那里他可以再次提交删除记录的操作。但是当我第二次尝试点击删除时,我收到以下错误:
在状态root.deleted.inFlight
中尝试处理事件deleteRecord
有人可以指导我可能存在的潜在问题吗?
我的参考代码:
文件:component.js
let person = this.get('person') -> this is the model
person.destroyRecord().then(() => {
// if success, show success message
this.showSuccessModel();
}, (error) => {
// show error message in a dialog, with close button
this.showErrorModel();
});
当用户点击关闭按钮,再次点击删除操作时,我收到上述错误。
答案 0 :(得分:2)
我能够解决这个问题,如果出现错误,我在模型对象上使用了rollBackAttributes()函数,正如ember文档所建议的那样,但我意识到我还必须这样做:
model.send(' becomeInvalid'),否则只是回滚属性不起作用。所以,我的工作代码看起来像这样:
let person = this.get('person') -> this is the model
person.destroyRecord().then(() => {
// if success, show success message
this.showSuccessModel();
}, (error) => {
// show error message in a dialog, with close button
if(person.get('hasDirtyAttributes') {
person.send('becameInvalid');
person.rollBackAttributes();
}
this.showErrorModel();
});