qq_39869526 2021-08-20 14:18 采纳率: 0%
浏览 37

类似tree 数组降维

请问向这样的一组数据 如何用 递归或者简洁的方式降维成 下面这样,把他们某个值拼在一起。

[
    {
        "name": "测试类目1/12321/1",
        "parentId": "2/5/125",
        "tagType": "category/product/brand"
    },
    {
        "name": "测试类目1/12321/1",
        "parentId": "2/5/125",
        "tagType": "category/product/brand"
    },
    {
        "name": "测试类目1/12321/1",
        "parentId": "2/5/125",
        "tagType": "category/product/brand"
    },
]


[
    {
      "id": 5,
      "name": "测试类目1",
      "description": null,
      "parentId": 2,
      "sort": 4,
      "tagType": "category",
      "configTagList": [
        {
          "id": 6,
          "name": "测试产品线1",
          "description": null,
          "parentId": 5,
          "sort": 5,
          "tagType": "product",
          "configTagList": [
            {
              "id": 131,
              "name": "2",
              "description": null,
              "parentId": 6,
              "sort": 129,
              "tagType": "brand",
            },
            {
              "id": 132,
              "name": "3",
              "description": null,
              "parentId": 6,
              "sort": 130,
              "tagType": "brand",
            },
            {
              "id": 133,
              "name": "4",
              "description": null,
              "parentId": 6,
              "sort": 131,
              "tagType": "brand",
            },
            {
              "id": 134,
              "name": "5",
              "description": null,
              "parentId": 6,
              "sort": 132,
              "tagType": "brand",
            },
            {
              "id": 135,
              "name": "6",
              "description": null,
              "parentId": 6,
              "sort": 133,
              "tagType": "brand",
            },
            {
              "id": 136,
              "name": "78",
              "description": null,
              "parentId": 6,
              "sort": 134,
              "tagType": "brand",
            }
          ]
        },
        {
          "id": 125,
          "name": "12321",
          "description": null,
          "parentId": 5,
          "sort": 123,
          "tagType": "product",
          "configTagList": [
            {
              "id": 126,
              "name": "123213",
              "description": null,
              "parentId": 125,
              "sort": 124,
              "tagType": "brand",
              "configTagList": [
                {
                  "id": 137,
                  "name": "1",
                  "description": null,
                  "parentId": 126,
                  "sort": 135,
                  "tagType": "model",
                },
                {
                  "id": 138,
                  "name": "2",
                  "description": null,
                  "parentId": 126,
                  "sort": 136,
                  "tagType": "model",
                },
                {
                  "id": 139,
                  "name": "3",
                  "description": null,
                  "parentId": 126,
                  "sort": 137,
                  "tagType": "model",
                },
                {
                  "id": 140,
                  "name": "34",
                  "description": null,
                  "parentId": 126,
                  "sort": 138,
                  "tagType": "model",
                }
              ]
            },
            {
              "id": 127,
              "name": "32432",
              "description": null,
              "parentId": 125,
              "sort": 125,
              "tagType": "brand",
            },
            {
              "id": 128,
              "name": "12",
              "description": null,
              "parentId": 125,
              "sort": 126,
              "tagType": "brand",
            },
            {
              "id": 129,
              "name": "3",
              "description": null,
              "parentId": 125,
              "sort": 127,
              "tagType": "brand",
            },
            {
              "id": 130,
              "name": "1",
              "description": null,
              "parentId": 125,
              "sort": 128,
              "tagType": "brand",
            }
          ]
        }
      ]
    },
    {
      "id": 21,
      "name": "测试类目2",
      "description": null,
      "parentId": 2,
      "sort": 19,
      "tagType": "category",
      "configTagList": [
        {
          "id": 22,
          "name": "测试产品线1",
          "description": null,
          "parentId": 21,
          "sort": 20,
          "tagType": "product",
          "configTagList": [
            {
              "id": 23,
              "name": "测试品牌1",
              "description": null,
              "parentId": 22,
              "sort": 21,
              "tagType": "brand",
              "configTagList": [
                {
                  "id": 24,
                  "name": "测试型号1",
                  "description": null,
                  "parentId": 23,
                  "sort": 22,
                  "tagType": "model",
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 5,
      "name": "测试类目1",
      "description": null,
      "parentId": 2,
      "sort": 4,
      "tagType": "category",
      "configTagList": [
        {
          "id": 6,
          "name": "测试产品线1",
          "description": null,
          "parentId": 5,
          "sort": 5,
          "tagType": "product",
          "configTagList": [
            {
              "id": 131,
              "name": "2",
              "description": null,
              "parentId": 6,
              "sort": 129,
              "tagType": "brand",
            },
            {
              "id": 132,
              "name": "3",
              "description": null,
              "parentId": 6,
              "sort": 130,
              "tagType": "brand",
            },
            {
              "id": 133,
              "name": "4",
              "description": null,
              "parentId": 6,
              "sort": 131,
              "tagType": "brand",
            },
            {
              "id": 134,
              "name": "5",
              "description": null,
              "parentId": 6,
              "sort": 132,
              "tagType": "brand",
            },
            {
              "id": 135,
              "name": "6",
              "description": null,
              "parentId": 6,
              "sort": 133,
              "tagType": "brand",
            },
            {
              "id": 136,
              "name": "78",
              "description": null,
              "parentId": 6,
              "sort": 134,
              "tagType": "brand",
            }
          ]
        }
      ]
    },
    {
      "id": 21,
      "name": "测试类目2",
      "description": null,
      "parentId": 2,
      "sort": 19,
      "tagType": "category",
      "configTagList": [
        {
          "id": 22,
          "name": "测试产品线1",
          "description": null,
          "parentId": 21,
          "sort": 20,
          "tagType": "product",
          "configTagList": [
            {
              "id": 23,
              "name": "测试品牌1",
              "description": null,
              "parentId": 22,
              "sort": 21,
              "tagType": "brand",
              "configTagList": [
                {
                  "id": 24,
                  "name": "测试型号1",
                  "description": null,
                  "parentId": 23,
                  "sort": 22,
                  "tagType": "model",
                }
              ]
            }
          ]
        }
      ]
    }
  ]
  • 写回答

3条回答 默认 最新

  • 崽崽的谷雨 2021-08-20 14:26
    关注

    递归循环。

    评论

报告相同问题?

问题事件

  • 创建了问题 8月20日

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料