灰烬:在一个请求中删除模型 [英] Ember: Remove models in one request

查看:68
本文介绍了灰烬:在一个请求中删除模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何用一行代码删除多个模型:

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

models.invoke('destroyRecord')

但这导致x调用x个物品。在Ember中是否有办法说一次调用删除所有将ID作为请求数据提交的模型

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?

当然可以通过编写自己的ajax请求来做到这一点

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.

推荐答案

Ember-Data不支持立即删除多个记录。 (也就是说,适配器和存储区实际上没有内置方法来执行此操作。)要进行一次AJAX调用,您必须自己进行调用(就像您所拥有的一样)。

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).

这篇关于灰烬:在一个请求中删除模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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