gpt4 book ai didi

javascript - 仅当选中复选框时才从 ng-repeat 中删除元素并控制台删除的值

转载 作者:行者123 更新时间:2023-11-27 23:34:19 30 4
gpt4 key购买 nike

嗨,我是 Angular 新手,在我的问题中,我可以在选中复选框时删除该行,但我想控制台删除的值

  var app = angular.module("appTable", []);
app.controller("Allocation", function($scope) {

$scope.dataList = [{
name: 'lin',
dept: 'b'
}, {
name: 'fie',
dept: 'bbbb'
}, {
name: 'test',
dept: 'aaa'
}];
$scope.add = function() {
var data = {};
data.name = '';
data.dept = '';
$scope.dataList.push(data);

};
$scope.remove = function() {
var newDataList = [];
angular.forEach($scope.dataList, function(v) {
if (!v.isDelete) {
newDataList.push(v);
}
});
$scope.dataList = newDataList;
console.log($scope.dataList)

};
});

我无法控制已删除的值 https://jsfiddle.net/7g9na001/

感谢任何帮助。提前致谢

最佳答案

您可以像这样在删除处理程序中记录对象内容。

JS 代码:

  $scope.remove = function() {
var newDataList = [];
angular.forEach($scope.dataList, function(v) {
if (!v.isDelete) {
newDataList.push(v);
} else {
//Value deleted from list
console.log("Value being removed :" + JSON.stringify(v));
}
});
$scope.dataList = newDataList;
console.log($scope.dataList);
};

Live Demo @ JSFiddle

关于javascript - 仅当选中复选框时才从 ng-repeat 中删除元素并控制台删除的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34262800/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com