2014-02-28 49 views
0

我不能從我的JSON API獲取和ID,我該怎麼做?我在我的刪除功能像$scope.info.id,但id不工作。geting json庫存ID使用資源

這裏是我的刪除功能

app.controller('InventoryCtrl', function($scope, $http, Inventory, $location) {  
    //getting the objects from Inventory 
     $scope.info = Inventory.query(); 

    $scope.deleteInv = function() { 
     Inventory.drop({id: $scope.info.id}, function() { 
      $location.path('/'); 
     }); 
    }; 
    }); 

這裏是我廠

app.factory('Inventory', function($resource, $http) { 
return $resource('http://localhost/api/v1/inventory/:id', {id: "@id"}, 
    { 
     drop: { 
      method: 'DELETE', 
      params: {id: "@id"} 
     } 
      } 
    ); 
}); 

這裏是我的API

{ 
meta: { 
limit: 20, 
next: null, 
offset: 0, 
previous: null, 
total_count: 3 
}, 
objects: [ 
{ 
category: {}, 
count: 1, 
created: "2014-02-28T11:54:02.831409", 
description: "dasdasdasdsa", 
id: 20, 
location: "asd", 
name: "adas11", 
resource_uri: "/api/v1/inventory/20", 
status: "sad" 
}, 
{ 
category: {}, 
count: 1, 
created: "2014-02-28T11:54:03.708003", 
description: "dasdasdasdsa", 
id: 21, 
location: "asd", 
name: "adas11", 
resource_uri: "/api/v1/inventory/21", 
status: "sad" 
}, 
] 
} 

回答

1

我不認爲你應該叫 「滴」功能。相反,您應該調用您在工廠中指定的「刪除」功能。

$scope.deleteInv = function() { 
    Inventory.delete({id: $scope.info.id}, function() { 
     $location.path('/'); 
}); 
+0

對不起,我拼錯了,我有':id'那裏,它不工作。我確實認爲我必須正確編寫這部分'Inventory.drop({id:$ scope.info.id}' – user3305175

+0

更改我的答案... – petur

+0

是的,但它不工作的id,它刪除所有對象,也許我需要'$ scope.info.objects.id?'或其他東西 – user3305175