I am currently developing in Angular and facing an issue with checkboxes that toggle a Boolean value to denote task completion. I have two arrays - one containing a list of objects and the other storing the first key values upon completion and clearance.
$scope.taskList = [{
complete: false,
foo: "1",
bar: "2",
baz: "3"
}];
$scope.completedTasks = [];
Although my function effectively clears tasks when one or two are selected, it struggles as the number of checked items increases. Only a fraction of the checked items get cleared at once, while invoking the function multiple times eventually clears all tasks individually. However, I am unable to figure out a way to clear the entire list in a single go.
$scope.clearComplete = function() {
for (var i = 0; i < $scope.taskList.length; i++) {
if ($scope.taskList[i].complete == true) {
$scope.completedTasks.push($scope.taskList[i].foo);
$scope.taskList.splice(i, 1);
}
}
console.log($scope.completedTasks);
return $scope.taskList;
};
I am struggling to correct the logic and would greatly appreciate any fresh perspectives on how to resolve this issue.
For this particular project, I aim to minimize dependencies and do not want to rely on external helper libraries like Underscore and Lodash.