为了账号安全,请及时绑定邮箱和手机立即绑定

vue递归查找id对应的对象

vue递归查找id对应的对象

千巷猫影 2019-08-17 09:40:48
将递归得到的对象push到数组中letselections=[];for(letleafofthis.tree){letresult=this.recursion(this.items,leaf);selections.push(result);}递归函数recursion(data,id){letresult;if(!data){return;}for(vari=0;i0){result=this.recursion(item.children,id);}}console.log(result);returnresult;},this.items为树结构的数据items:[{id:1,name:'VuetifyHumanResources',children:[{id:2,name:'Coreteam',children:[{id:201,name:'John'},{id:202,name:'Kael'},{id:203,name:'Nekosaur'},{id:204,name:'Jacek'},{id:205,name:'Andrew'}]},{id:3,name:'Administrators',children:[{id:301,name:'Ranee'},{id:302,name:'Rachel'}]},{id:4,name:'Contributors',children:[{id:401,name:'Phlow'},{id:402,name:'Brandon'},{id:403,name:'Sean'}]}]},{id:5,name:'Example',children:[{id:501,name:'qaz'}]},{id:6,name:'Qdd',children:[{id:601,name:'yui'}]}],tree为树选中的数据[201,202,203]在递归中我想要得到id所在的对象,在第一个方法中push到数组中形成一个数组集合,现在递归方法出现了问题得到的result为undefined,请各位帮我看下?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1307 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信