Ember.js 当我创建对象失败422时,如何不在列表中添加余烬数据?
我把它叫做Ember.js 当我创建对象失败422时,如何不在列表中添加余烬数据?,ember.js,ember-data,Ember.js,Ember Data,我把它叫做产品,在/productsurl中创建新产品。页面看起来像: 当我提交创建产品表单时将发送操作创建产品: DEBUG: ------------------------------- DEBUG: Ember : 2.8.1 DEBUG: Ember Data : 2.8.0 DEBUG: jQuery : 2.2.4 DEBUG: Ember Simple Auth : 1.1.0 DEBUG: -
产品
,在/products
url中创建新产品。页面看起来像:
当我提交创建产品表单时
将发送操作创建产品
:
DEBUG: -------------------------------
DEBUG: Ember : 2.8.1
DEBUG: Ember Data : 2.8.0
DEBUG: jQuery : 2.2.4
DEBUG: Ember Simple Auth : 1.1.0
DEBUG: -------------------------------
问题是,当我的产品名称为空时,服务器将返回422
,错误消息将以产品形式显示,但产品列表将添加一个,如下所示:
而这个空对象并没有保存在服务器中,只是显示在浏览器中。我认为如果服务器返回422
对象就不会添加到列表中
那么有一个很好的解决方案吗?谢谢
actions: {
createProduct() {
let product = this.store.createRecord('product', {
name: this.get('name'),
...
});
theWorkItem.save().then(()=> {
...
}, ()=> {
this.set('workItemErrors', theWorkItem.get('errors'));
});
},
...