$http.delete 在 foreach 中不工作

$http.delete not working inside foreach

我正在尝试从网格中删除行。在 foreach 函数中,我需要调用 $http.delete 来从数据库中删除。下面是我在另一个类似问题的帮助下编写的代码。请告知有什么问题。它达到了 $http.delete 但没有拨打电话。

var promises = [];

angular.forEach($scope.gridApi.selection.getSelectedRows(),
  function (data, index) 
  { $scope.gridOptions.data.splice($scope.gridOptions.data.lastIndexOf(data), 1);
    promises.push($scope.deleteRow(data._id));            
  }
); 

$q.all(promises).then(
function success(){alert("Delete successful");},
function failure(err){alert("Error in deletion");}
);

$scope.deleteRow = function(rowId)
{
    return $http.delete('http://localhost:8080/deleterecords/' + data._id);
}

deleteRow 函数中,您无权访问 data。 您应该将代码更改为:

$scope.deleteRow = function(rowId) {
    return $http.delete('http://localhost:8080/deleterecords/' + rowId);
}