js不规则多维数组递归
function traverse(obj) { for (var a in obj) { if (typeof (obj[a]) == "object") { traverse(obj[a]); //递归遍历 } else { // console.log(obj) if(obj.departmentId==itemData.departmentOrgId){ sureArrDepart=obj; return; } // console.log(a + "=" + obj[a]); //如果是值就显示 } } } traverse([res])
或
let datas = [] //是一个树结构的数据 setName(datas){ //遍历树 获取id数组 for(var i in datas){ this.expandedKeys.push(datas[i].id) if(datas[i].children){ this.setName(datas[i].children); } } },
https://blog.csdn.net/qq_38734862/article/details/105910665
遍历树
//回显 baseTree(datas, sureids) { let that = this; //遍历树 获取id数组 for (var i in datas) { that.$refs.tree.setChecked(datas[i].targetId, false); for (let j = 0; j < sureids.length; j++) { if (datas[i].targetId == sureids[j]) { that.$refs.tree.setChecked(datas[i].targetId, true); } } if (datas[i].listChildrenNode && datas[i].listChildrenNode.length > 0) { this.baseTree(datas[i].listChildrenNode, sureids); } } return; }, }, }; </s