类似tree 数组降维处理。

152 阅读2分钟

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

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

\

`原数据`


` 
[
    {
      "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",
                }
              ]
            }
          ]
        }
      ]
    }
  ]`