2014-09-03 73 views
1

請幫我明白了:爲什麼angularjs不刪除對象angularjs刪除對象的數組

$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 
      } 
     }); 
    }]); 

對象數組:
[{

file: "storage/dave-macvicar-1130x1130.jpg", 
id: 377, 
is_external: false, 
size: 272543, 
status: "unknown", 
type: "image/jpeg", 
upload_type: 1, 
uploaded: "2014-09-03" }, {...same objects, with different id}, {}] 

角度發送到服務器:
/api/v1/documents/storage?0=%7B%22webkitRelativePath%22:%22%22,%22lastModifiedDate%22:%222014-08-19T14:11:17.000Z%22,%22name%22:%22Screenshot從+ + 2014年8月19日+ 18:11:16.png%22%22type%22:%22image%2Fpng%22%22size%22:607898,%22id%22:381,%22upload_type%22: 1,%22user%22:%22%D0%A8%D0%B8%D1%80%D0%BE%D0%BA%D0%BE%D0%B2 +%D0%90%D0%BB%D0%B5% D0%BA%D1%81%D0%B5%D0%B9 +%D0%A1%D0%B5%D1%80%D0%B3%D0%B5%D0%B5%D0%B2%D0%B8%D1% 87%22%22file%22:%22storage%2F0ccf78bc333a11e48c4bb8030570fabc%2FScreenshot +從+ 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 
+0

你有沒有添加'ngResourse'模塊以及其他模塊? – Jai 2014-09-03 07:33:11

+0

是的,我做到了。 我用正確的方式嗎? – madjardi 2014-09-03 07:35:28

+1

DELETE不允許您以與POST相同的方式發送數據。 – Kasyx 2014-09-03 07:40:20

回答

1

您可以將IDS用於通過queryString刪除,幾乎是這樣的:

http://localhost:3030/api/books?TENANTID=xxx&q=%5B1,3%5D 

%5B等於[

%5D等於]

所以未轉換的網址應該是這樣的:

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