一個數組如何過濾另外一個數組中的值,以下圖和代碼
一個數組擁有所有數據
另外一個數組只擁有部分數據
擁有所有數組數組要根據擁有部分數據的數組,過濾獲得新的數組vue
let allRoutes = [ { path: '/', name: 'home', component: () => import('@/views/Home.vue'), children: [ { path: '/role', name: 'role', meta: { tile: '角色' }, component: () => import('@/views/role/index.vue'), redirect: '/role/list', children: [ { path: 'create', name: 'roleCreate', meta: { tile: '建立角色' }, component: () => import('@/views/role/create.vue') }, { path: 'list', name: 'roleList', meta: { tile: '角色列表' }, component: () => import('@/views/role/list.vue') }, { path: 'update', name: 'roleUpdate', meta: { tile: '修改角色' }, component: () => import('@/views/role/update.vue') } ] }, { path: '/adminUser', name: 'adminUser', meta: { tile: '管理員' }, component: () => import('@/views/adminUser/index.vue'), children: [ { path: 'create', name: 'adminUserCreate', meta: { tile: '建立管理員' }, component: () => import('@/views/adminUser/create.vue') }, { path: 'list', name: 'adminUserList', meta: { tile: '管理員列表' }, component: () => import('@/views/adminUser/list.vue') }, { path: 'update', name: 'adminUserUpdate', meta: { tile: '修改管理員' }, component: () => import('@/views/adminUser/update.vue') } ] } ] }, { path: '*', name: '404', component: () => import('@/views/404.vue') } ]
相比所有數據的數組,沒有了name: 'roleCreate',
數組
let someRoutes = [ { name: 'home', children: [ { name: 'role', children: [{ name: 'roleList' }, { name: 'roleUpdate' }] }, { name: 'adminUser', children: [ { name: 'adminUserCreate' }, { name: 'adminUserList' }, { name: 'adminUserUpdate' } ] } ] } ]