繁体   English   中英

我如何从Angular.js中的数组中删除某个对象

[英]How can i remove a certain object from array in Angularjs

我有复选框树。 部门和每个部门下都有一些用于员工的复选框。 当用户检查部门时,将在此部门下选择所有员工。 我将唯一的部门键添加到数组中。 我的问题是如何从阵列中删除未经检查的部门密钥。

$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);
    }

如果您只想删除对象的键,则可以通过以下方式进行操作:

m.forEach(function (dept) {

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

当然,这只是一个模糊的示例,我将需要知道您的实际对象定义才能为您提供正确的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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