How to delete all records associated with an ember model without clearing local Storage?

后端 未结 1 938
醉酒成梦
醉酒成梦 2021-01-12 15:13

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

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 16:02

    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);
      });
    

    See this jsBin.

    0 讨论(0)
提交回复
热议问题