第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

數(shù)組中如何按照規(guī)則篩選對(duì)象?

數(shù)組中如何按照規(guī)則篩選對(duì)象?

至尊寶的傳說 2019-03-07 14:14:12
const router = [    {        path: '/hello',        icon: 'hammer',        name: 'hello',        title: '你好',        children: [            { path: 'index', title: '你好', name: 'hello_index' },            { path: 'index1', title: '你好1', name: 'hello_index1' }        ]    },    {        path: '/hello1',        icon: 'hammer',        name: 'hello1',        title: '你好',        children: [            { path: 'index2', title: '你好2', name: 'hello_index2' },            { path: 'index3', title: '你好3', name: 'hello_index3' },            { path: 'index4', title: '你好3', name: 'hello_index4' }        ]    },    {        path: '/hello2',        icon: 'hammer',        name: 'hello2',        title: '你好',        children: [            { path: 'index4', title: '你好4', name: 'hello_index4' },            { path: 'index5', title: '你好5', name: 'hello_index5' }        ]    }]let routernone = [    {        path: '/hello2',        children: []    },    {        path: '/hello1',        children: [            'index2', 'index3'        ]    }];請問如何在 router 以 routernone 為規(guī)則 篩選出新數(shù)組,routernone中表明,不取path為'/hello2'的,不取path為'/hello1'的children中 path為index2的和path為index3的,
查看完整描述

3 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

暴力篩選,能做的只是優(yōu)化暴力程度;

let router = [

    {

        path: '/hello',

        icon: 'hammer',

        name: 'hello',

        title: '你好',

        children: [

            { path: 'index', title: '你好', name: 'hello_index' },

            { path: 'index1', title: '你好1', name: 'hello_index1' }

        ]

    },

    {

        path: '/hello1',

        icon: 'hammer',

        name: 'hello1',

        title: '你好',

        children: [

            { path: 'index2', title: '你好2', name: 'hello_index2' },

            { path: 'index3', title: '你好3', name: 'hello_index3' },

            { path: 'index4', title: '你好3', name: 'hello_index4' }

        ]

    },

    {

        path: '/hello2',

        icon: 'hammer',

        name: 'hello2',

        title: '你好',

        children: [

            { path: 'index4', title: '你好4', name: 'hello_index4' },

            { path: 'index5', title: '你好5', name: 'hello_index5' }

        ]

    }

]

let routernone = {

    '/hello2': [],

    '/hello1': ['index2', 'index3']

}



router = router.filter((route, index) => {

     if (routernone[route.path]){

        if (routernone[route.path].length > 0) {

            route.children = route.children.filter((child)=> {

                return routernone[route.path].indexOf(child.path) <= -1

            })

            

            return true

        } else {

            return false

        }

    } else {

        return true

    }

})



console.log(router)


查看完整回答
反對(duì) 回復(fù) 2019-03-28
?
湖上湖

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊

為什么要多加一個(gè)用于篩選的呢,直接在第一個(gè)對(duì)象列表中加標(biāo)志不就好了,


const router = [

    {

        path: '/hello',

        icon: 'hammer',

        name: 'hello',

        title: '你好',

        children: [

            { path: 'index', title: '你好', name: 'hello_index' },

            { path: 'index1', title: '你好1', name: 'hello_index1' }

        ]

    },

    {

        path: '/hello1',

        icon: 'hammer',

        name: 'hello1',

        title: '你好',

        children: [

            { path: 'index2', title: '你好2', name: 'hello_index2',meta: {noshow:true} },

            { path: 'index3', title: '你好3', name: 'hello_index3' ,meta: {noshow:true}},

            { path: 'index4', title: '你好3', name: 'hello_index4' }

        ]

    },

    {

        path: '/hello2',

        icon: 'hammer',

        name: 'hello2',

        title: '你好',

        meta: {noshow:true},

        children: [

            { path: 'index4', title: '你好4', name: 'hello_index4' },

            { path: 'index5', title: '你好5', name: 'hello_index5' }

        ]

    }

]


在運(yùn)行時(shí)判斷一下meta里的noshow是true,就不顯示不就好了


查看完整回答
反對(duì) 回復(fù) 2019-03-28
?
富國滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

let router = [

    {

        path: '/hello',

        icon: 'hammer',

        name: 'hello',

        title: '你好',

        children: [

            { path: 'index', title: '你好', name: 'hello_index' },

            { path: 'index1', title: '你好1', name: 'hello_index1' }

        ]

    },

    {

        path: '/hello1',

        icon: 'hammer',

        name: 'hello1',

        title: '你好',

        children: [

            { path: 'index2', title: '你好2', name: 'hello_index2' },

            { path: 'index3', title: '你好3', name: 'hello_index3' },

            { path: 'index4', title: '你好3', name: 'hello_index4' }

        ]

    },

    {

        path: '/hello2',

        icon: 'hammer',

        name: 'hello2',

        title: '你好',

        children: [

            { path: 'index4', title: '你好4', name: 'hello_index4' },

            { path: 'index5', title: '你好5', name: 'hello_index5' }

        ]

    }

];

let routernone = [

    { path: '/hello2'}

];

let routernone2 = [

     {

        path: '/hello1',

        children: [

            'index2', 'index3'

        ]

    }

];

router = router.filter(item => {

    return routernone.findIndex( i => item.path == i.path) == -1;

}).map(item => {

    

    let temp = routernone2.find(i => i.path == item.path);

    if(temp){

        item.children = item.children.filter(ii => !temp.children.find(iii => iii == ii.path));

    } 

    return item;

});


查看完整回答
反對(duì) 回復(fù) 2019-03-28
  • 3 回答
  • 0 關(guān)注
  • 617 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)