0

我无法从我的 json api 获取和 ID,我该怎么做?我$scope.info.id在我的删除功能中这样做,但 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"
},
]
}
4

1 回答 1

1

我不认为你应该调用“drop”函数。相反,您应该调用您在工厂中指定的“删除”功能。

$scope.deleteInv = function () {
    Inventory.delete({id: $scope.info.id}, function() {
        $location.path('/');
});
于 2014-02-28T11:41:28.443 回答