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;