js如何实现树形数组的筛选?
问题描述
给定一个这样的数组arr
var arr=[{
"name": "Baseinfo",
"children": [{
"name": "Baseinfo_School",
"children": [{
"name": "Baseinfo_Test"
}]
}, {
"name": "Baseinfo_Teacher"
}]
}]
如何从这个数组test中筛选出相同的结构
var test = [{
path: '/baseinfo',
//组件名
name: 'Baseinfo',
component: Home,
children: [{
path: '/baseinfo/school',
name: 'Baseinfo_School',
component: BaseinfoSchool,
children: [{
path: '/baseinfo/school/test',
name: 'Baseinfo_Test',
component: BaseinfoSchoolTest
} ]
},
{
path: '/baseinfo/teacher',
name: 'Baseinfo_Teacher',
component: BaseinfoTeacher,
children: [{
path: '/baseinfo/teacher/test',
name: 'Baseinfo_Test1',
component: BaseinfoTeacherTest
} ]
},
]
},
{
path: '/others',
name: 'Others',
component: Others
}
]
得到这样的结果result,就是去除了other项和baseinfoTeacherTest项
var result = [{
path: '/baseinfo',
//组件名
name: 'Baseinfo',
component: Home,
children: [{
path: '/baseinfo/school',
name: 'Baseinfo_School',
component: BaseinfoSchool,
children: [{
path: '/baseinfo/school/test',
name: 'Baseinfo_Test',
component: BaseinfoSchoolTest
} ]
},
{
path: '/baseinfo/teacher',
name: 'Baseinfo_Teacher',
component: BaseinfoTeacher
},
]
}
]
数据结构小白,那位大佬可以写个案例吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)