Ember: Remove models in one request

白昼怎懂夜的黑 提交于 2019-12-11 23:17:35

问题


I know how to delete multiple models with one line of code:

models.invoke('destroyRecord')

But this results in x calls voor x items. Is there a way to say in Ember Remove all models with one call, where the ids are submitted as request data?

Of course I can do it by writing my own ajax request

models.invoke('deleteRecord');
Ember.$.ajax({
    url: ...,
    type: 'DELETE',
    data: JSON.stringify( models.map(function(model) { return parseInt(model.get('id')); }) ),
    contentType: 'application/json'
 }).then(function() {
     ...
 },function(reason) {
     ...
 });

but i wonder if something like this is already in the core.


回答1:


Ember-Data doesn't support deleting multiple records at once out of the box. (That is to say, the adapters and store don't really have built-in methods to do so.) To do it it one AJAX call, you'll have to make the call yourself (like you have).



来源:https://stackoverflow.com/questions/25113960/ember-remove-models-in-one-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!