nodejs -- 迭代器
阿新 • • 發佈:2018-12-15
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))