如何通过其 ID 删除 Ember 数据记录

编程入门 行业动态 更新时间:2024-10-18 22:37:27
本文介绍了如何通过其 ID 删除 Ember 数据记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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:关键词]

本文发布于:2023-03-31 10:39:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/801871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   ID   Ember

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!