左又 2023-02-09 18:52 采纳率: 50%
浏览 31
已结题

多维数组对象根据数组值筛选

根据uriList中存在的值在menuAll中使用value筛选数据,等到全新的menuAll,层级不变


```typescript
const uriList = [
        '/home/zxgg',
        '/comanyProducts/allProduct',
        '/article/xwg',
        '/article/cwbx',
        '/article/jrxx',
        '/financialProductInfo',
        '/verificationManage/0',
        '/verificationManage/1',
        '/verificationManage/2',
    ]
    const menusAll = [{
        label: '首页',
        value: '1',
        icon: () => h(HomeOutlined),
        children: [{
            value: '/home/zxgg',
            label: '最新公告'
        }]
    }, {
        label: '公司产品',
        value: '2',
        icon: () => h(ProductOutlined),
        children: [{
            value: '/comanyProducts/allProduct',
            label: '全部产品'
        }]
    }, {
        label: '公司特色',
        value: '3',
        icon: () => h(UserManagementOutlined),
        children: [{
            label: '消费者权益保护',
            children: [{
                value: '/article/xfz_jy',
                label: '消费者教育',
            }, {
                value: '/article/xfz_gg',
                label: '消保公告',
            }, {
                value: '/article/xfz_fz',
                label: '反诈剧场',
            }, {
                value: '/article/xfz_zn',
                label: '客户投诉指南',
            }]
        }, {
            label: '标签管理',
            value: '/labelManage/xfz'
        }],
    }, {
        label: '关于我们',
        value: '4',
        icon: () => h(UserManagementOutlined),
        children: [{
            label: '媒体中心',
            children: [{
                value: '/article/mtbd',
                label: '媒体报道',
            }, {
                value: '/article/xwg',
                label: '新闻稿',
            }]
        }]
    }, {
        label: '信息披露',
        value: '5',
        icon: () => h(UnorderedListOutlined),
        children: [{
            value: '/article/cwbx',
            label: '财务表现'
        }, {
            value: '/article/zygg',
            label: '重要公告'
        }, {
            label: '金融信息',
            children: [{
                value: '/article/jrxx',
                label: '金融信息',
            }, {
                value: '/financialProductInfo',
                label: '产品信息查询'
            }, {
                value: '/financialInsurance',
                label: '保险信息披露'
            }, {
                value: '/financialFinancepartner',
                label: '银行机构披露'
            }],
        }]
    }, {
        label: '客户服务',
        value: '6',
        icon: () => h(BellOutlined),
        children: [{
            label: '帮助与支持',
            children: [{
                value: '/article/scjwt',
                label: '常见问题'
            }, {
                value: '/article/swzyh',
                label: 'wzyhApp'
            }, {
                value: '/article/swld',
                label: 'wld'
            }, {
                value: '/article/swyd',
                label: 'wyd'
            }, {
                value: '/article/swcd',
                label: 'wcd'
            }, {
                value: '/article/sqyapp',
                label: 'qyAPP'
            }, ]
        }, {
            label: '标签管理',
            value: '/labelManage'
        }]
    }, {
        label: '核查管理',
        value: '7',
        icon: () => h(CheckSquareOutlined),
        children: [{
            label: '全部',
            value: '/verificationManage/0'
        }, {
            label: '待核查',
            value: '/verificationManage/1'
        }, {
            label: '已审核',
            value: '/verificationManage/2'
        }],
    }];
    

```

  • 写回答

2条回答 默认 最新

  • 左又 2023-05-24 11:06
    关注
    
    function filterMenus(list, uri) {
        return list.reduce((res,item) => {
            if(item.children) item.children = filterMenus(item.children,uri)
            if(uri.includes(item.value) || item.children?.length) res.push(item)
            return res;
        },[])
    }
    menusAll.map(v => ({...v,children:filterMenus(v.children, uriList)}))
    menusAll.filter(item => item.children.length > 0)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月1日
  • 已采纳回答 5月24日
  • 创建了问题 2月9日

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大