数据操作处理(数组拼接,去重)

1.数组处理添加与拼接

          this.treeListData.push(res.payload.results.OADepartment);
                  var treeList = this.treeListData[0].children;
                  var treeL = [];
                  treeList.forEach(el =>{
                      if(el.children){
                        treeL.push(el.children);//添加到数组
                      }
                  });
                  var treeLi = [];
                  var len = treeL.length;
                  for(var i=0;i<len;i++){
                    treeLi.push.apply(treeLi,treeL[i]);//拼接数组
                  }
                  this.listSecondDepart = treeLi;

2.数组对象排重reduce()

var hash = {};
            var arr = this.listCheckDepart;
            arr = arr.reduce(function(item, next) {
                hash[next.id] ? '' : hash[next.id] = true && item.push(next);
                return item
            }, [])
            this.listCheckDepart = arr;

猜你喜欢

转载自www.cnblogs.com/cx709452428/p/9712252.html
今日推荐