我通過使用JavaScript splice()
方法刪除表格行數據時遇到問題。但我不能刪除數據,同時刪除數組的第一行和最後一行。如何使用javascript從數組中刪除特定的行?
$ scope.StudentDetails是我的數組包含了像ID,姓名,部門,年齡,地址的所有數據,
$scope.deleteData = function (item)
{
var index = $scope.StudentDetails.indexOf(item);
if (index > -1)
{
$scope.StudentDetails.splice(index, 1);
}
};
在第一幅圖像,我會點擊刪除然後顯示在下面的圖像..但不刪除確切的數據。 我正在使用上面的編碼。
使用下面的代碼加載我的數據並推送到數組並在表格元素中填充日期。
$scope.Load = function()
{
$scope.StudentDetails = [];
$http({ method: 'GET', url: '/Home/GetStudentDetails' }).success(function (data)
{
if (data != null)
{
$.each(data.Data, function (index, value)
{
$scope.StudentDetails.push(value);
});
// $scope.checked = false;
}
}).error(function()
{
alert("Failed");
});
}
請幫助任何人! 在此先感謝!
你可以發佈更多的代碼(包括刪除第一個/最後一個條目)? – David
'item'是什麼? – Praveen
該項目,其中包含行ID ... – Sankar