问题描述
使用 Ember Data,我想知道如何删除记录,因为我知道它的 id.
With Ember Data, I would like to know how to delete a record given that I know its id.
推荐答案
注意调用rec.deleteRecord()
后还需要调用rec.save()
提交"删除.
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();
});
通过在上面的 JSBin 中添加一条记录(http://jsbin/iwiruw/458/edit),删除它,然后重新加载页面.在页面重新加载后(或者如果您单击使用 JS 运行"按钮),您将看到记录复活".这是添加了 rec.save()
的 jsbin,您可以在其中看到记录没有恢复.
You can see that this is necessary by adding a record in the JSBin above (http://jsbin/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/iwiruw/460/edit
这篇关于如何通过其 ID 删除 Ember 数据记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论