Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 当我创建对象失败422时,如何不在列表中添加余烬数据?_Ember.js_Ember Data - Fatal编程技术网

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'));
    });
  },
...