ember.js - ember删除记录,第一次尝试后无法删除
问题描述
我有一个必须删除记录的工作流程,但如果后端抛出任何错误,我会显示一个错误对话框,上面有一个关闭按钮。用户可以关闭该错误对话框并返回主屏幕,在那里他可以再次提交删除记录的操作。但是当我第二次尝试单击删除时出现以下错误:
尝试
deleteRecord
在 root.deleted.inFlight 状态下处理事件
有人可以指导我潜在的问题是什么吗?
我的参考代码:
文件: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();
});
当用户单击关闭按钮时,当他再次单击删除操作时,我收到上述错误。
解决方案
我能够解决这个问题,如果出现错误,我按照 ember 文档的建议在模型对象上使用 rollBackAttributes() 函数,但我刚刚意识到我还必须这样做:
model.send('becameInvalid'),否则只是回滚属性不起作用。因此,我的工作代码将如下所示:
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();
});
推荐阅读
- python - 将文本字符串拆分为 int 和 text 变量
- sql-server - 在 Azure Functions 上使用 Microsoft 报表查看器
- javascript - 如何在 React 中将 connect() 和 withStyles() 用于类组件?
- php - 如何从 Codeigniter 中的返回结果运行多个查询
- scala - 如果我修改指向缓存 rdd 的变量会发生什么?
- laravel - Laravel 项目在共享主机上使用 bitbucket 管道
- docker - 在 Kubernetes pod 中使用 docker socket
- python - 错误:“make: * [Makefile:163: all] 错误 2”和“make: * [Makefile:163: all] 中断”
- snowflake-cloud-data-platform - 单一模式上的雪花授予选择
- javascript - Angular JS将多个数组传递给scope.list