如何删除与余烬模型相关联的所有记录,而不清除本地存储? [英] How to delete all records associated with an ember model without clearing local Storage?

查看:124
本文介绍了如何删除与余烬模型相关联的所有记录,而不清除本地存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经扩展了此 stackoverflow答案有一个程序,一次删除所有的记录。但是,删除仅在批处理中发生,并且不会一次删除所有内容。

I have extended the program given in this stackoverflow answer to have a program that deletes all the records all at once. However, the deletion happens only in batches and does not delete everything all at once.

这是我在这个 JSBin

deleteAllOrg: function(){
  this.get('store').findAll('org').then(function(record){
    record.forEach(function(rec) {
        console.log("Deleting ", rec.get('id'));
        rec.deleteRecord();
        rec.save();
    });
    record.save();
  });
}

任何想法如何修改程序,以便可以删除所有记录一旦?

Any idea how the program can be modified such that all records can be deleted at once?

我也尝试过model.destroy()和model.invoke('deleteRecords'),但它们不起作用。

I have also tried model.destroy() and model.invoke('deleteRecords') but they don't work.

非常感谢任何帮助。感谢您的帮助!

Any help is greatly appreciated. Thanks for your help!

推荐答案

调用 deleteRecord() forEach 将打破循环。您可以通过在 Ember.run.once 函数中包含删除代码来修复它,如下所示:

Calling deleteRecord() within forEach will break the loop. You can fix it by wrapping the delete code in an Ember.run.once function like this:

  this.get('store').findAll('org').then(function(record){
     record.content.forEach(function(rec) {
        Ember.run.once(this, function() {
           rec.deleteRecord();
           rec.save();
        });
     }, this);
  });

请参阅此jsBin

这篇关于如何删除与余烬模型相关联的所有记录,而不清除本地存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆