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

「ドロップ」関数を呼び出す必要はないと思います。代わりに、ファクトリで指定した「削除」関数を呼び出す必要があります。

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