如何通过其ID删除Ember Data记录 [英] How to delete Ember Data record by its ID
问题描述
注意:如果使用Ember Data,我想知道如何删除记录。在调用 rec.deleteRecord()
之后,您还需要调用 rec.save()
来提交删除。
this.get('store')。find('model',the_id_of_the_record).then(function(rec)
rec.deleteRecord();
rec.save();
});
您可以通过在上述JSBin中添加记录( http://jsbin.com/iwiruw/458/edit ),删除它,然后重新加载页面。在页面重新加载后(或者单击使用JS运行按钮),您将看到该记录复活。这里有一个添加了 rec.save()
的jsbin,您可以看到这些记录不会恢复生效。
http://jsbin.com/iwiruw/460/edit
With Ember Data, I would like to know how to delete a record given that I know its id.
Note that after calling rec.deleteRecord()
you also need to call rec.save()
to "commit" the deletion.
this.get('store').find('model', the_id_of_the_record).then(function(rec){
rec.deleteRecord();
rec.save();
});
You can see that this is necessary by adding a record in the JSBin above (http://jsbin.com/iwiruw/458/edit), deleting it, and then reloading the page. You'll see that the record is "resurrected" after the page reloads (or if you click the "Run with JS" button). Here's a jsbin with rec.save()
added, where you can see that the records do not come back to life.
http://jsbin.com/iwiruw/460/edit
这篇关于如何通过其ID删除Ember Data记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!