Layui(十八) Layui 自定义两个数据对象是否有相等元素,有则剔除

目的:

           把原本arr1 中含有arr2 的数据对象剔除

过程:

//剔除未联动点中的已联动点
        function cleanData(arr1, arr2) {
            console.log("原始数据", arr1, arr2);
            for (let i = 0; i < arr1.length; i++) {
                let childata1 = arr1[i]['children'];
                for (let x = 0; x < arr2.length; x++) {
                    // console.log('未联动', childata1[x]);
                    let childata2 = arr2[x]['children'];
                    for (let y = 0; y < childata2.length; y++) {
                        // console.log('已联动', childata2[y]);
                        if (JSON.stringify(childata1[x]) === JSON.stringify(childata2[y])) {
                            //去除与已联动点相同的数据,留下删除后的数据
                            childata1.splice(i, 1);
                        }
                    }
                }
            }
            TreeTable(arr1);
            TreeTable1(arr2)

        }

 

PS:  注意数据格式,不要直接使用

      ①、 arr1数据

"data":[{"id":0,"name":"192.168.1.167","children":[{"id":68,"name":"167","pname":"167_辅助输出"},{"id":68,"name":"167","pname":"167_门锁"}]},{"id":1,"name":"192.168.1.168","children":[{"id":69,"name":"168","pname":"168_辅助输出"},{"id":69,"name":"168","pname":"168_门锁"}]

        ②、 arr2数据

"data":[{"id":0,"name":"192.168.1.167","children":[{"id":68,"name":"167","pname":"167_辅助输出"}]},{"id":1,"name":"192.168.1.168","children":[{"id":69,"name":"168","pname":"168_门锁"}]}

 

你可能感兴趣的:(layui)