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 EmberJS CRUD:deletedRecord在链接到后继续重新出现_Ember.js_Ember Data - Fatal编程技术网

Ember.js EmberJS CRUD:deletedRecord在链接到后继续重新出现

Ember.js EmberJS CRUD:deletedRecord在链接到后继续重新出现,ember.js,ember-data,Ember.js,Ember Data,我在从Ember.JS模型中删除记录时遇到问题 我在我的把手模板中有一个记录概览,每行有一个删除按钮 单击按钮时,我希望从表中删除该行(并在RESTAPI上执行删除) 我的把手模板包含下表+每个记录的删除按钮 <table class="table table-hover"> <tr> <th>Latitude</th> <th>Longitude</th> <th>Accuracy&

我在从Ember.JS模型中删除记录时遇到问题

我在我的把手模板中有一个记录概览,每行有一个删除按钮

单击按钮时,我希望从表中删除该行(并在RESTAPI上执行删除)

我的把手模板包含下表+每个记录的删除按钮

<table class="table table-hover">
  <tr>
    <th>Latitude</th>
    <th>Longitude</th>
    <th>Accuracy</th>
    <th></th>
  </tr>
  {{#each model}}
    <tr>
    <td>{{latitude}}</td>
    <td>{{longitude}}</td>
    <td>{{accuracy}}</td>
    <td><button {{action removeItem this target="view"}}>Delete</button></td>
    </tr>
  {{/each}}
</table>
我的控制器如下所示:

App.LocationsIndexController = Ember.ArrayController.extend({
  removeItem: function(location) {
    console.log("Removing location " + location);

    location.one("didDelete", this, function() {
      console.log("record deleted");
      this.get("target").transitionTo("locations");
    });

    location.deleteRecord();
    this.get("store").commit();
  }
});
调用removietem方法,从表中删除项,并在RESTAPI上调用DELETE。太好了

然而

如果我切换到另一个模板(使用linkTo)并返回到概览表(再次使用linkTo),删除的记录将重新显示在表中。 它不再存在于后端,因此无法再次删除:

Uncaught Error: Attempted to handle event `deleteRecord` on <App.Location:ember356:517d96d7658c51de1c000027> while in state rootState.deleted.saved. Called with undefined 
Uncaught Error:试图处理上的事件'deleteRecord',看起来很有希望(实际上显示了我要实现的删除按钮),但结果却完全不同

我想了解删除的项目重新出现的原因,以及如何避免。我也尝试在ArrayController中调用this.removeObject(location),但删除的记录会不断重新出现

我可以使用浏览器控制台重现该问题

  • locs=App.Location.find()
  • locs.content.length//返回5
  • newLoc=App.Location.createRecord({纬度:120,经度:120})
  • locs=App.Location.find()
  • locs.content.length//返回6
  • newLoc.deleteRecord()
  • locs.content.length//返回5
  • locs=App.Location.find()
  • locs.content.length//返回6(为什么在这里返回6?

此问题是由于ember.js/ember-data.js中的错误或2之间的兼容性问题引起的

当我从builds.emberjs.com站点获取最新的一对余烬和余烬数据时,这个问题在某个时候得到了解决

有了这个组合,delete工作得很好

  • locs=App.Location.find()
  • locs.content.length//返回5
  • newLoc=App.Location.createRecord({纬度:120,经度:120})
  • locs=App.Location.find()
  • locs.content.length//返回6
  • newLoc.deleteRecord()
  • locs.content.length//返回5
  • locs=App.Location.find()
  • locs.content.length/现在返回5,与之前返回的位置一样返回6
因此,在使用ember数据时,始终确保它与您正在使用的ember.js兼容。发布最新版本的ember和ember数据的EmberJS持续集成应该通过测试套件,并且应该被认为是兼容的

Uncaught Error: Attempted to handle event `deleteRecord` on <App.Location:ember356:517d96d7658c51de1c000027> while in state rootState.deleted.saved. Called with undefined