像这种文件库目录的,不知道每层有多少层子层,如何遍历目录,然后把该目录显示出来呢
已知的是下面这样的json数组呢
我想把这样的目录以文件名为节点在小程序中显示出来,这json数组层层嵌套,不会遍历呢
使用递归的方式遍历数据
可以参考.,之前写的动态路由的一些代码
function filterRouters(routers) {
let access = []
routers.forEach(router => {
let routerJson = {}
routerJson['path'] = router.navigationPath
routerJson['name'] = router.navigationName
if (router.child && router.child.length > 0) {
routerJson['children'] = filterRouters(router.child)
}
access.push(routerJson)
});
return access
}
有帮助,望采纳