2016-03-15 51 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