使用递归遍历树状结构数据
生活随笔
收集整理的這篇文章主要介紹了
使用递归遍历树状结构数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
遞歸遍歷樹狀結構
datas:[{id: 1,name: '分組1',expand: true,type:'group',editable:false,active:false,children: [{id: 2,expand: true,name: '相機1',type:'camera',editable:false,active:false,}] },{id: 3,expand: true,name: '分組2',type:'group',editable:false,active:false,children: [{id: 5,expand: true,name: '分組2-1',type:'group',editable:false,active:false,children: [{id: 6,expand: true,name: '相機2-1',type:'camera',editable:false,active:false,},{id: 7,expand: true,name: '相機2-2',type:'camera',editable:false,active:false,}]}]}],// 遍歷樹形結構 traverseSingle(item,paramsId){if(item.id==paramsId){console.log('========',item.id,paramsId)} }, traverseTree(data,paramsId){const _this = this;if(!data){return;}for(let i=0;i<data.length;i++){_this.traverseSingle(data[i],paramsId);if(data[i].children && data[i].children.length>0){_this.traverseTree(data[i].children,paramsId);}}// console.log('==id====',paramsId) },總結
以上是生活随笔為你收集整理的使用递归遍历树状结构数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装Windows10时遇到的0x803
- 下一篇: html网页清楚内外边距