在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 使用splice去除數(shù)組中指定的的項,結(jié)果不對

使用splice去除數(shù)組中指定的的項,結(jié)果不對

使用splice去除數(shù)組中指定的的項,結(jié)果不對
如下的代碼,我需要保留children.path===allOrder || children.path===accessPage的項

    let routers = [
        {
            path: '/index',
            name: 'Index',
            children: [{
                path: 'accountManagement',
                name: 'accountManagement',
                meta: { title: '權(quán)限管理', icon: 'el-icon-setting' }
            }]
        },
        {
            path: '/index',
            name: 'paltform logs',
            meta: { title: '平臺日志', icon: 'el-icon-menu' },
            children: [{
                    path: 'UserBehavior',
                    meta: { title: '用戶行為' },
                    name: 'UserBehavior'
                }, {
                    path: 'errorOrder',
                    meta: { title: '錯誤訂單' },
                    name: 'errorOrder'
                }, {
                    path: 'statisticRecharge',
                    meta: { title: '統(tǒng)計充值' },
                    name: 'StatisticRecharge'
                },
                {
                    path: 'allOrder',
                    meta: { title: '所有訂單' },
                    name: 'allOrder'
                }, {
                    path: 'userRechargeError',
                    meta: { title: '用戶充值總金額錯誤' },
                    name: 'userRechargeError'
                }
            ]
        },
        {
            path: '/index',
            name: 'wechat api',
            meta: { title: '微信接口', icon: 'el-icon-menu' },
            children: [{
                path: 'chart',
                meta: { title: '訪問趨勢' },
                name: 'Chart'
            }, {
                path: 'visitDistribution',
                meta: { title: '訪問分布' },
                name: 'VisitDistribution'
            }, {
                path: 'accessRetention',
                meta: { title: '訪問留存' },
                name: 'AccessRetention'
            }, {
                path: 'accessPage',
                meta: { title: '訪問頁面' },
                name: 'accessPage'
            }, {
                path: 'userPortrait',
                meta: { title: '用戶畫像' },
                name: 'UserPortrait'
            }, {
                path: 'payStatistics',
                meta: { title: '付費統(tǒng)計' },
                name: 'PayStatistics'
            }]
        }
    ]

 
    function filterAsyncRouter(Router) {
        console.log(Router)
      if(Router && Router.length){
        for(let i=0;i<Router.length;i++){
            if(Router[i].name && Router[i].children){
              for(let k=0;k<Router[i].children.length;k++){
                  if(!hasPermissionName(Router[i].children[k].name)){
                    Router[i].children.splice(k,1)
                    k++
                  }
              }
            }
          
        }
      }
      console.log(Router)
    }

   function hasPermissionName(routerName) {
       let permissions = ['allOrder','accessPage']
      for (let i = 0; i < permissions.length; i++) {
        if(permissions[i]===routerName){
          return true
        }
      }
    }

    filterAsyncRouter(routers)

圖片描述

回答
編輯回答
浪蕩不羈

k++改成k--

2018年6月15日 22:50