AngularJs使用分页删除嵌套分组行上的记录
我试图构建一个简单的页面来分组记录,然后添加一个按钮来删除一些记录 问题是,如果删除的记录是第一个,则所有分组数据都将被删除 我认为问题在于拆分分组数组时: 普朗克AngularJs使用分页删除嵌套分组行上的记录,angularjs,Angularjs,我试图构建一个简单的页面来分组记录,然后添加一个按钮来删除一些记录 问题是,如果删除的记录是第一个,则所有分组数据都将被删除 我认为问题在于拆分分组数组时: 普朗克 你主要做错了两件事: 尝试在结果中删除与报告中相同的索引 当该行中有更多项时,将在结果中擦除 可能的(工作)修复方法是: $scope.deleteItem = function(item,row){ var lastInRow = true; var index=$scope.reports.indexOf(item)
你主要做错了两件事:
$scope.deleteItem = function(item,row){
var lastInRow = true;
var index=$scope.reports.indexOf(item);
$scope.reports.splice(index,1);
//check if any more items match that name (or in the same row)
for (var i=0; i<$scope.reports.length; ++i) {
if ($scope.reports[i].name == item.name) {
lastInRow = false;
break;
}
}
$scope.noOfPages = Math.ceil($scope.reports.length / $scope.pageSize);
$scope.pages.then(function(result){
//get the relevant index for the result array
var resultIndex = result.indexOf(item.name);
//if it matches and it isn't the last one - erase that row
if (result && result[index] == item.name && lastInRow) {
result.splice(resultIndex,1);
}
$scope.noOfPages = Math.ceil(result.length / $scope.pageSize);
$scope.currentPage = 1;
})
};
$scope.deleteItem=函数(项,行){
var lastInRow=真;
var index=$scope.reports.indexOf(项目);
$scope.reports.splice(索引1);
//检查是否还有其他项目与该名称匹配(或在同一行中)
对于(var i=0;i
$scope.deleteItem = function(item,row){
var lastInRow = true;
var index=$scope.reports.indexOf(item);
$scope.reports.splice(index,1);
//check if any more items match that name (or in the same row)
for (var i=0; i<$scope.reports.length; ++i) {
if ($scope.reports[i].name == item.name) {
lastInRow = false;
break;
}
}
$scope.noOfPages = Math.ceil($scope.reports.length / $scope.pageSize);
$scope.pages.then(function(result){
//get the relevant index for the result array
var resultIndex = result.indexOf(item.name);
//if it matches and it isn't the last one - erase that row
if (result && result[index] == item.name && lastInRow) {
result.splice(resultIndex,1);
}
$scope.noOfPages = Math.ceil(result.length / $scope.pageSize);
$scope.currentPage = 1;
})
};