前端遍历tree结构将数组里最后一个children添加标识

原始数据:

      dataList: [

        {

          id: 1,

          label: '标题1',

          children: [

            {

              id: 2,

              label: '一级 1-1',

              children: [

                {

                  id: 3,

                  label: '二级 1-1-1',

                },

                {

                  id: 4,

                  label: '三级',

                  type: '1',

                  children: [

                    {

                      id: 5,

                      label: '四级 1-1-1',

                    },

                    {

                      id: 6,

                      label: '四级 1-1-2',

                    },

                    {

                      id: 7,

                      label: '四级 1-1-3',

                    },

                  ],

                },

              ],

            },

          ],

        },

      ]

期望数据:

dataList: [{

          id: 1,

          label: '标题1',

type: '1',

          children: [

            {

              id: 2,

              label: '一级 1-1',

type: '1',

              children: [

                {

                  id: 3,

                  label: '二级 1-1-1',

type: '1',

                },

                {

                  id: 4,

                  label: '三级',

                  type: '1',

                  children: [

                    {

                      id: 5,

                      label: '四级 1-1-1',

type: '1',

                    },

                    {

                      id: 6,

                      label: '四级 1-1-2',

                    },{

                      id: 7,

                      label: '四级 1-1-3',

** type: '2',**

                    },

                  ],

                },

              ],

            },

          ],

        },

      ]

也就是说最后一个type为2 最后个之前的children添加的type为1

回答

image.png

image.png

以上是 前端遍历tree结构将数组里最后一个children添加标识 的全部内容, 来源链接: utcz.com/a/42736.html

回到顶部