第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

用子數(shù)組展平數(shù)組

用子數(shù)組展平數(shù)組

守候你守候我 2023-04-27 16:42:49
我有一個(gè)看起來像這樣的數(shù)組[{    "entity": {        "id": "2387232d-5fc4-4344-b71b-42f70ff16040",        "pid": "bdba6327-4055-42db-8f2e-34c595a6f79f",        "name": "Outsourcing Lead",        "title": "OL"    },    "childNodes": [        {            "entity": {                "id": "91444f59-1b70-4817-a9a5-8e9b85a9799a",                "pid": "2387232d-5fc4-4344-b71b-42f70ff16040",                "name": "Corporate Accountant",                "title": "CA"            },            "childNodes": [],            "depth": 2,            "parent": {                "id": "2387232d-5fc4-4344-b71b-42f70ff16040",                "pid": "bdba6327-4055-42db-8f2e-34c595a6f79f",                "name": "Outsourcing Lead",                "title": "OL"            }        },        {            "entity": {                "id": "4454e911-d1dc-494d-b243-e3237b9971d7",                "pid": "2387232d-5fc4-4344-b71b-42f70ff16040",                "name": "Liaison Officer / Messenger",                "title": "LO"            },            "childNodes": [                {                    "entity": {                        "id": "893b5911-eb46-4bb3-a3eb-ac375f959202",                        "pid": "4454e911-d1dc-494d-b243-e3237b9971d7",                        "name": "System Administrator",                        "title": "SYSAD"                    },                    "childNodes": [],                    "depth": 3,                    "parent": {                        "id": "4454e911-d1dc-494d-b243-e3237b9971d7",                        "pid": "2387232d-5fc4-4344-b71b-42f70ff16040",                        "name": "Liaison Officer / Messenger",                        "title": "LO"                    }                }            ],我已經(jīng)在這個(gè)線程上搜索并嘗試了答案合并/展平數(shù)組數(shù)組展平鋸齒狀的多維數(shù)組var flattened = [].concat.apply([], data);“數(shù)據(jù)”變量是我的數(shù)組。但它不起作用。感謝任何幫助。謝謝。
查看完整描述

1 回答

?
富國滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以采用迭代和遞歸方法并使用Array#flatMap.

這種方法只需要entity對(duì)象。

const

? ? getFlat = ({ entity, childNodes }) => [entity, ...childNodes.flatMap(getFlat)],

? ? array = [{ entity: { id: "2387232d-5fc4-4344-b71b-42f70ff16040", pid: "bdba6327-4055-42db-8f2e-34c595a6f79f", name: "Outsourcing Lead", title: "OL" }, childNodes: [{ entity: { id: "91444f59-1b70-4817-a9a5-8e9b85a9799a", pid: "2387232d-5fc4-4344-b71b-42f70ff16040", name: "Corporate Accountant", title: "CA" }, childNodes: [], depth: 2, parent: { id: "2387232d-5fc4-4344-b71b-42f70ff16040", pid: "bdba6327-4055-42db-8f2e-34c595a6f79f", name: "Outsourcing Lead", title: "OL" } }, { entity: { id: "4454e911-d1dc-494d-b243-e3237b9971d7", pid: "2387232d-5fc4-4344-b71b-42f70ff16040", name: "Liaison Officer / Messenger", title: "LO" }, childNodes: [{ entity: { id: "893b5911-eb46-4bb3-a3eb-ac375f959202", pid: "4454e911-d1dc-494d-b243-e3237b9971d7", name: "System Administrator", title: "SYSAD" }, childNodes: [], depth: 3, parent: { id: "4454e911-d1dc-494d-b243-e3237b9971d7", pid: "2387232d-5fc4-4344-b71b-42f70ff16040", name: "Liaison Officer / Messenger", title: "LO" } }], depth: 2, parent: { id: "2387232d-5fc4-4344-b71b-42f70ff16040", pid: "bdba6327-4055-42db-8f2e-34c595a6f79f", name: "Outsourcing Lead", title: "OL" } }], depth: 1, parent: null }],

? ? flat = array.flatMap(getFlat);


console.log(flat);

.as-console-wrapper { max-height: 100% !important; top: 0; }


查看完整回答
反對(duì) 回復(fù) 2023-04-27
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)