Closed sailei1 closed 3 years ago
findItemById(id,array,key,childKey){ let rs=[]; function find(id,arr,key,childKey) { if(rs.length>0){return} if(!Array.isArray(arr)){return} let obj= arr.find((item) => { return item[key]==id; }) if(!obj){ return arr.forEach((item)=>{ find(id,item[childKey],key,childKey,obj) }) }else{ rs.push(obj); } } find(id,array,key,childKey); return rs[0]; }, let obj = this.findItemById(permissionId, target, 'id', 'children')