账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    如何两个数组作对比,生成一个符合要求的新数组
    12
    0
    数组对比,根据node节点的变化,生成一个符合要求的新数组//原数据const arr = [ { "id": "12020000", "nameEn": "Group", "children": [ { "id": "12020100", "nameEn": "123", }, { "id": "12020200", "nameEn": "1232", } ], }, { "id": "12030000", "nameEn": "info", "children": [ { "id": "12030100", "nameEn": "Level", }, { "id": "12030200", "nameEn": " Class", }, { "id": "12030300", "nameEn": " Trading", }, { "id": "12030400", "nameEn": " Platform", }, { "id": "12030500", "nameEn": " with Ecosystem", }, { "id": "12030600", "nameEn": " Market", } ] }, { "id": "12104000", "nameEn": "Trading", "children": [ { "id": "12104100", "nameEn": "Buy", }, { "id": "12104200", "nameEn": "put", }] }, { "id": "12200000", "nameEn": "Trading", "children": [ { "id": "12200100", "nameEn": "save", }, { "id": "12200110", "nameEn": "save1", }, ] }, ]// 当node的节点为const node = ['12020100', '12030100', '12020000', '12030000']result = [{ "id": "12020000", "nameEn": "Group", "children": [ { "id": "12020100", "nameEn": "123", }]}, { "id": "12030000", "nameEn": "info", "children": [ { "id": "12030100", "nameEn": "Level", }]}]// 此时,选择了一个节点 12020200node = ['12020100', '12030100', '12020200', '1211000', '12030000']// result 变更为result = [{ "id": "12030000", "nameEn": "info", "children": [ { "id": "12030100", "nameEn": "Level", }]}, { "id": "12020000", "nameEn": "Group", "children": [ { "id": "12020100", "nameEn": "123", }, { "id": "12020200", "nameEn": "1232", }]},]// 此时,选择了一个节点 12104100node = ['12100100', '12030100', '12020200', '12104100', '1211000', '12030000', '12104000']// result 变更为result = [{ "id": "12030000", "nameEn": "info", "children": [ { "id": "12030100", "nameEn": "Level", }]}, { "id": "12020000", "nameEn": "Group", "children": [ { "id": "12020100", "nameEn": "123", }, { "id": "12020200", "nameEn": "1232", }]}, { "id": "12104000", "nameEn": "Trading", "children": [ { "id": "12104100", "nameEn": "Buy", }]},]// 此时,选择了一个节点 12030200node = ['12100100', '12030100', '12020200', '12104100', '12030200', '1211000', '12030000', '12104000']// result 变更为result = [{ "id": "12020000", "nameEn": "Group", "children": [ { "id": "12020100", "nameEn": "123", }, { "id": "12020200", "nameEn": "1232", }]}, { "id": "12104000", "nameEn": "Trading", "children": [ { "id": "12104100", "nameEn": "Buy", }]}, { "id": "12030000", "nameEn": "info", "children": [ { "id": "12030100", "nameEn": "Level", }, { "id": "12030200", "nameEn": " Class", },]}]
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版

    回答动态

    师傅被妖怪抓走了:发布了悬赏问题火爆全网的“元宇宙”到底是什么?预计能赚取 1积分收益
    酒后略带风情:发布了悬赏问题Android内存中Graphics与Code占用过高预计能赚取 10积分收益
    扛起拖把扫天下:发布了悬赏问题typescript如何导出接口配置?求解,谢谢!预计能赚取 10积分收益
    发布了悬赏问题Vue 如何改变返回页面的路径?如让B页面只能返回到A页面.预计能赚取 11积分收益
    发布了悬赏问题vue H5移动端;底部bottom固定定位,安卓弹起键盘导致页面变形如何解决?预计能赚取 10积分收益
    发布了悬赏问题请问为什么tomcat8.5 GET请求中文正常,POST请求还需要设置UTF-8.预计能赚取 10积分收益
    发布了悬赏问题vue2.5+ts创建以及引入jq的方法预计能赚取 11积分收益
    情场浪女:发布了悬赏问题import ggplot时报错module 'pandas' has no attribute 'tslib'预计能赚取 10积分收益
    见心书画许老师18753375161:发布了悬赏问题echarts3 legend禁止点击事件,允许悬浮事件预计能赚取 11积分收益
    aa_92cb0bd09f:发布了悬赏问题codewar上的一个问题预计能赚取 11积分收益