如何删除与余烬模型相关联的所有记录,而不清除本地存储?
我已经扩展了此 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 。