如何使用一组 id 以 angular 4 进行大量删除 [英] How to make a massive delete in angular 4 with an array of ids
问题描述
我正在尝试进行大量删除,为了做到这一点,我有一个 Array
想要删除的 ID.我无法将此数组作为参数传递给方法 this._httpService.delete(uri,options)
._httpService
的类型是 Http
.
I'm trying to make a massive delete, in order to do that I have an Array<number>
of the ids I want to delete. I can't pass this array as a parameter to the method this._httpService.delete(uri,options)
. The type of _httpService
is Http
.
所以我循环数组并在循环内进行单次调用,但每次调用都是异步的,当循环结束时我有一定的逻辑要运行.
So I'm looping the array and inside the loop I'm making single calls, but each call is async and I have certain logic to run when the loop ends.
推荐答案
实际上你可以在 DELETE 请求的正文中发送 id 数组,根据 这个答案,像这样:
Actually you can send the id array in the body of a DELETE request, according to this answer, like so:
http.delete('/api/something', new RequestOptions({
headers: headers,
body: anyObject // this would contain your ids
}))
因此,与其发出数百个请求,不如让您的应用在正文中创建一个包含所有 ID 的请求.
So instead of issuing hundreds of requests, have your app make just one with all ids in the body.
这篇关于如何使用一组 id 以 angular 4 进行大量删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!