angularjs删除对象数组
请帮助我理解:为什么angularjs不删除对象数组angularjs删除对象数组,angularjs,rest,restful-url,angularjs-resource,Angularjs,Rest,Restful Url,Angularjs Resource,请帮助我理解:为什么angularjs不删除对象数组 $scope.removeAll = function( all = _.pluck($scope.uploader.queue, 'file'); all.length && HTTPStorage.query_delete(all, function () { $scope.uploader.clearQueue(); delay.resol
$scope.removeAll = function(
all = _.pluck($scope.uploader.queue, 'file');
all.length && HTTPStorage.query_delete(all,
function () {
$scope.uploader.clearQueue();
delay.resolve();
});
)
服务:
services.factory('HTTPStorage', ['$resource', function($resource){
return $resource('/api/v1/documents/storage/:id', {'id': '@id'},{
'query_delete': {
method: 'DELETE',
isArray: true
}
});
}]);
对象数组:[{ 已发送到服务器:
/22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22-2014-2014-8-8-8-8-8-8-10-19-19-19-19-19-19-19-19-19-19 19-19-19-19 19 19 19 19-19 19 19 19 19 19 19 19:19 19 19 19 19 19 19:19 19 19 19 19 19 19 19 19:14:14:19 19 19 19 19:19 19 19 19 19 19 19 19 19 19 19 19 19 19 19:10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10%B5%D0%B9+%D0%A1%D0%B5%D1%80%D0%B3%D0%B5%D0%B2%D0%B8%D1%87%22,%22文件%22:%22存储%2F0ccf78bc333a11e48c4bb8030570fabc%2from+201……的屏幕截图及更多符号 如何向服务器发送对象数组以删除这些对象
如果使用“卷曲所有法线”:
curl -X DELETE -H 'Content-Type: application/json' http://127.0.0.1:8000/api/v1/documents/storage -d '[{"id": 330}, {"id": 333}]' -u user:pass
您可以通过queryString发送要删除的ID,大致如下:
http://localhost:3030/api/books?TENANTID=xxx&q=%5B1,3%5D
%5B等于[
%5D等于]
因此,未转换的url应该如下所示:
http://localhost:3030/api/books?TENANTID=xxx&q=[1,3]
在您的代码中,可以这样写:
...
.factory('BookEntity', ['$resource', function ($resource) {
return $resource(
'/api/books/:id',
{id: '@id'},
{
create: {method: 'POST'},
update: {method: 'PUT'}
}
);
}])
...
ScriptEntity.delete({q: JSON.stringify(bookIds)}) //bookIds is an array contains of Ids you want to delete
您是否已将
ngresource
模块与其他模块一起添加?是的,我添加了。我是否使用了正确的方法?删除不允许您以与POST相同的方式发送数据。使用POST而不是DELETE:)好吧……要删除更多数据,我使用POST。最简单的方法。
...
.factory('BookEntity', ['$resource', function ($resource) {
return $resource(
'/api/books/:id',
{id: '@id'},
{
create: {method: 'POST'},
update: {method: 'PUT'}
}
);
}])
...
ScriptEntity.delete({q: JSON.stringify(bookIds)}) //bookIds is an array contains of Ids you want to delete