Two recursive functions are used

let that = this; function checkPrevious(data,parent){ data.forEach((item,index)=>{ if(item.id== that.activeID){ if(index ! = 0){ if(data[index-1].children.length ! ==0){ that.findID(data[index-1].children[data[index-1].children.length-1]); }else{// console.log(' no child node ') thate. activeID = data[index-1].id; that.content = data[index-1].content; } }else{ if(parent){ that.activeID = parent.id; that.content = parent.content; }else{ that.isPre = false; } // console.log(' parent has no child node ') // console.log(parent,' parent has no child node ')}}else{// console.log(data, '-----data') checkPrevious(item.children,item) } }) }; checkPrevious(data) findID(data){ if(data.children.length ! = 0){ this.findID(data.children[data.children.length-1]) }else{ this.activeID = data.id; this.content = data.content; }},Copy the code