简体   繁体   中英

How can i remove a certain object from array in Angularjs

i have tree of checkboxes . Departments and under each department there are some checkboxes for employees. when user check on department all employees are selected under this department. I add the unique departments keys to an array. My problem is how to remove the unchecked department key from the array.

$scope.leftdept = function (m) {

        console.log(m);

        for (i = 0; i < m.length; i++) {
            if ($scope.depts.indexOf(m[i].Dep_key) === -1) {
                $scope.depts.push(m[i].Dep_key);
            }

       console.log($scope.depts);
    }

If you just want to remove the key of object then you can do it this way:

m.forEach(function (dept) {

if(condition) // this is where you check if this department is checked or unchecked
    delete dept[Dep_key];
});

Of course this only a vague example, I will need to know your actual object definition to give you a proper answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM