2016-03-15 101 views
0

我想从网格中删除行。在一个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); 
} 
+0

什么是错误?您可以提供的任何代码片段? –

+0

您是否在浏览器开发人员工具的Javascript控制台中查找错误? –

+0

感谢Johannes!..刚接触javascript调试,是的,因为你建议我检查浏览器开发工具,并且在控制台选项卡中有错误... as squaleLis below below,data error for data variable! – higujral

回答

0

deleteRow功能,您没有访问更多的data。 您应该将您的代码更改为:

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

哎呀...谢谢squaleLis – higujral

+0

如果解决了,请将我的答案标记为已接受:) – squaleLis

+1

当然,我只是在等待测试以确认没有其他东西被破坏:)...在这里你走了! – higujral