nodejs--ディエゼル

1464 ワード




function filterAsyncRouter(asyncRouterMap, maps) {


  const accessedRouters = asyncRouterMap.filter(route => { // router.path       /        

    if ( route.path.endsWith()) { //           
      if (route.children && route.children.length) {
        route.children = filterAsyncRouter(route.children, maps.children)
      }
      return true
    }



    return false
  })



  return accessedRouters
}



let access = [
  {path: '/coin',children:[{path:'index'}]},
  {path: '/block',children:[{path:'coin'}]},
  {path:'/icon',children:[{path:'index'}]}
]


let  maps = [
    {url:'/coin',children:[{url:'index'}]},
    {url:'/block',children:[{url:''},{url:''}]},
    {url:'/icon'}
  ]

function accessFilter(maps, access) {

  const accessedRouters = access.filter((item) => {
    for (let i = 0; i < maps.length; i++) {
      if(maps[i].children){
        if (item.path === maps[i].url){
          if (item.children && maps[i].children){
            item.children = accessFilter(maps[i].children,item.children)
          }
          // if(maps.children){
          //   return true
          // } else {
          //   return false
          // }
          return true;
        }
      }

    }
    return false
  })
  return accessedRouters
}

var a = accessFilter(maps,access)
console.log(JSON.stringify(a))