SOURCE

const data = [
    {
        "children": [
            {
                "id": "b753",
                "industry_id": 3,
                "is_hide": 0,
                "name": "看机会",
                "pid": "b396"
            },
            {
                "id": "b8069",
                "industry_id": 3,
                "is_hide": 0,
                "name": "薪水期望",
                "pid": "b396"
            }
        ],
        "id": "b396",
        "industry_id": 3,
        "is_hide": 0,
        "name": "候选人看机会",
        "pid": 0
    },

    {
        "children": [
            {
                "id": "b8086",
                "industry_id": 3,
                "is_hide": 0,
                "name": "再联系",
                "pid": "b8085"
            },
            {
                "id": "b9126",
                "industry_id": 3,
                "is_hide": 0,
                "name": "要简历",
                "pid": "b8085"
            },
            {
                "id": "b9127",
                "industry_id": 3,
                "is_hide": 0,
                "name": "加微信",
                "pid": "b8085",
                children: [{
                    name: 'hello world',
                    id: 2333,
                    children: [{
                        name: 'hhhhhhhhhhhhhhhhhhh',
                        id: 2444
                    }]
                }]
            }
        ],
        "id": "b8085",
        "industry_id": 3,
        "is_hide": 0,
        "name": "todo",
        "pid": 0
    },

    {
        "children": [

            {
                "create_at": "Wed, 27 Jan 2021 17:55:37 GMT",
                "create_by": 5,
                "id": "c3",
                "is_delete": 0,
                "is_leaf": 1,
                "name": "✏️ 联系人非决策人",
                "order": 0,
                "organization_id": 1,
                "pid": "c77",
                "trackers_count": 1,
                "update_at": "Mon, 27 Jun 2022 21:28:28 GMT",
                "update_by": 5,
                "version": 1
            },
            {
                "create_at": "Wed, 27 Jan 2021 18:03:10 GMT",
                "create_by": 25,
                "id": "c5",
                "is_delete": 0,
                "is_leaf": 1,
                "name": "✏️ 处理异议",
                "order": 0,
                "organization_id": 1,
                "pid": "c77",
                "trackers_count": 1,
                "update_at": "Mon, 27 Jun 2022 21:28:28 GMT",
                "update_by": 69,
                "version": 1
            },
            {
                "create_at": "Wed, 27 Jan 2021 18:05:44 GMT",
                "create_by": 7,
                "id": "c6",
                "is_delete": 0,
                "is_leaf": 1,
                "name": "✏️ 夸赞产品",
                "order": 0,
                "organization_id": 1,
                "pid": "c77",
                "trackers_count": 1,
                "update_at": "Mon, 27 Jun 2022 21:28:28 GMT",
                "update_by": 7,
                "version": 1
            },
            {
                "create_at": "Wed, 27 Jan 2021 20:52:15 GMT",
                "create_by": 5,
                "id": "c7",
                "is_delete": 0,
                "is_leaf": 1,
                "name": "✏️ 下次联络时间",
                "order": 0,
                "organization_id": 1,
                "pid": "c77",
                "trackers_count": 1,
                "update_at": "Mon, 27 Jun 2022 21:28:28 GMT",
                "update_by": 5,
                "version": 1
            },

        ],
        "create_at": "Wed, 27 Jan 2021 17:54:35 GMT",
        "create_by": 5,
        "id": "c77",
        "is_delete": 0,
        "is_leaf": 0,
        "name": "✏️ 自定义",
        "order": 0,
        "organization_id": 1,
        "pid": 0,
        "trackers_count": 0,
        "update_at": "Mon, 27 Jun 2022 21:28:28 GMT",
        "update_by": 7,
        "version": 1
    },
    {
        "children": [
            {
                "create_at": "Mon, 27 Jun 2022 21:14:50 GMT",
                "create_by": 2264,
                "id": "c91",
                "is_delete": 0,
                "is_leaf": 1,
                "name": "✏️ 产品",
                "order": 1,
                "organization_id": 1,
                "pid": "c90",
                "trackers_count": 1,
                "update_at": "Mon, 27 Jun 2022 21:14:50 GMT",
                "update_by": 2264,
                "version": 1
            },
            {
                "create_at": "Mon, 25 Jul 2022 14:14:30 GMT",
                "create_by": 10415,
                "id": "c141",
                "is_delete": 0,
                "is_leaf": 1,
                "name": "✏️ hao",
                "order": 2,
                "organization_id": 1,
                "pid": "c90",
                "trackers_count": 1,
                "update_at": "Mon, 25 Jul 2022 14:14:30 GMT",
                "update_by": 10415,
                "version": 16
            }
        ],
        "create_at": "Mon, 27 Jun 2022 21:14:50 GMT",
        "create_by": 2264,
        "id": "c90",
        "is_delete": 0,
        "is_leaf": 0,
        "name": "✏️ 测试",
        "order": 1,
        "organization_id": 1,
        "pid": 0,
        "trackers_count": 0,
        "update_at": "Mon, 27 Jun 2022 21:14:50 GMT",
        "update_by": 2264,
        "version": 1
    },


]


function getExpandedData(list, res = []) {
    for (const item of list) {
        const arr = []
        arr.push({
            id: item.id,
            name: item.name
        })
        if (item.children) {
            getExpandedData(item.children, arr)
        }
        res.push(...arr)
    }
    return res
}

const res = getExpandedData(data, [])
console.log(res)
console 命令行工具 X clear

                    
>
console