//扁平化,找爸爸
let arr = [
{
code: '4801102',
name: '低点枪机',
id: '1286f1b8f60f4bf283eecc6aadc1b51d',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '低点枪机',
key: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
code: '4801106',
name: '倾斜摄影',
id: 'dbd77d09ab244fcdba6177ec82798821',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '倾斜摄影',
key: 'dbd77d09ab244fcdba6177ec82798821',
},
{
code: '4801105',
name: '全景VR',
id: 'f8cc3d3048ca48059189019a27d675ee',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '全景VR',
key: 'f8cc3d3048ca48059189019a27d675ee',
},
{
code: '4801104',
name: '区域NVR',
id: '15e1164016214dada8470d4da05c7c83',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '区域NVR',
key: '15e1164016214dada8470d4da05c7c83',
},
{
code: '4801103',
name: '海康人脸',
id: 'a05bca905d3a42cca43471658179c2e9',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '海康人脸',
key: 'a05bca905d3a42cca43471658179c2e9',
},
{
code: '',
name: '监控区域',
id: 'a20e8ac3e4a54dcc94178d7d59a87acb',
sort: 100,
parent_ids: '0,',
parentId: '0',
title: '监控区域',
key: 'a20e8ac3e4a54dcc94178d7d59a87acb',
},
{
code: '4801101',
name: '高点全景',
id: '2bacf588947f4a29abdd8e9c4fda1a2b',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '高点全景',
key: '2bacf588947f4a29abdd8e9c4fda1a2b',
},
{
code: '4801100',
name: '高点球机',
id: '992984199da1489390174615fa6a9bc4',
sort: 100,
parent_ids: '0,a20e8ac3e4a54dcc94178d7d59a87acb,',
parentId: 'a20e8ac3e4a54dcc94178d7d59a87acb',
title: '高点球机',
key: '992984199da1489390174615fa6a9bc4',
},
{
title: '全景VR通道-01',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: '73692fde887f4f329cab9af143fbed16',
id: '73692fde887f4f329cab9af143fbed16',
key: '73692fde887f4f329cab9af143fbed16',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '全景VR通道-02',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: '324a669b89a4436a8c8c695a28d2425e',
id: '324a669b89a4436a8c8c695a28d2425e',
key: '324a669b89a4436a8c8c695a28d2425e',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '全景VR通道-03',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: '7404a95683724398bc9697bc7b1e24d0',
id: '7404a95683724398bc9697bc7b1e24d0',
key: '7404a95683724398bc9697bc7b1e24d0',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '全景VR通道-04',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: '2021ee5c0d3b4cf9a1b9ee0d7718569b',
id: '2021ee5c0d3b4cf9a1b9ee0d7718569b',
key: '2021ee5c0d3b4cf9a1b9ee0d7718569b',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '全景VR通道-05',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: 'e6a8332540694341ac4fb57cd941ebbc',
id: 'e6a8332540694341ac4fb57cd941ebbc',
key: 'e6a8332540694341ac4fb57cd941ebbc',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '全景VR通道-06',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: 'ffc89ebc47164a66b5fc06b64699a56f',
id: 'ffc89ebc47164a66b5fc06b64699a56f',
key: 'ffc89ebc47164a66b5fc06b64699a56f',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '全景VR通道-07',
RegionID: 'f8cc3d3048ca48059189019a27d675ee',
ChannelID: '4c37c0ea8d2b47b092f095d04effc0af',
id: '4c37c0ea8d2b47b092f095d04effc0af',
key: '4c37c0ea8d2b47b092f095d04effc0af',
parentId: 'f8cc3d3048ca48059189019a27d675ee',
},
{
title: '华为_18.202_AR球机(室内)',
RegionID: '992984199da1489390174615fa6a9bc4',
ChannelID: 'f4aeb2bccf6d44389ec29f8beb5a3a40',
id: 'f4aeb2bccf6d44389ec29f8beb5a3a40',
key: 'f4aeb2bccf6d44389ec29f8beb5a3a40',
parentId: '992984199da1489390174615fa6a9bc4',
},
{
title: '大华18.215',
RegionID: '992984199da1489390174615fa6a9bc4',
ChannelID: '760dc07f29534f18afc29d8409b4540c',
id: '760dc07f29534f18afc29d8409b4540c',
key: '760dc07f29534f18afc29d8409b4540c',
parentId: '992984199da1489390174615fa6a9bc4',
},
{
title: '大华全景拼接18.201',
RegionID: '2bacf588947f4a29abdd8e9c4fda1a2b',
ChannelID: 'd6b1aa1c980b486bac02337c27cfab4d',
id: 'd6b1aa1c980b486bac02337c27cfab4d',
key: 'd6b1aa1c980b486bac02337c27cfab4d',
parentId: '2bacf588947f4a29abdd8e9c4fda1a2b',
},
{
title: '大华全景球机18.201',
RegionID: '2bacf588947f4a29abdd8e9c4fda1a2b',
ChannelID: 'cd1e5c4acc86437a89b9d91776812fa6',
id: 'cd1e5c4acc86437a89b9d91776812fa6',
key: 'cd1e5c4acc86437a89b9d91776812fa6',
parentId: '2bacf588947f4a29abdd8e9c4fda1a2b',
},
{
title: '天鹅湖',
RegionID: 'dbd77d09ab244fcdba6177ec82798821',
ChannelID: 'df40dd86308e46848ad8962a53de31b7',
id: 'df40dd86308e46848ad8962a53de31b7',
key: 'df40dd86308e46848ad8962a53de31b7',
parentId: 'dbd77d09ab244fcdba6177ec82798821',
},
{
title: '海康全景拼接28.128',
RegionID: '2bacf588947f4a29abdd8e9c4fda1a2b',
ChannelID: '7d576bbf7e95422987c9d28ececc5b95',
id: '7d576bbf7e95422987c9d28ececc5b95',
key: '7d576bbf7e95422987c9d28ececc5b95',
parentId: '2bacf588947f4a29abdd8e9c4fda1a2b',
},
{
title: '海康全景球机28.128',
RegionID: '2bacf588947f4a29abdd8e9c4fda1a2b',
ChannelID: '9ae482848a514a20aacb2d4c882acd78',
id: '9ae482848a514a20aacb2d4c882acd78',
key: '9ae482848a514a20aacb2d4c882acd78',
parentId: '2bacf588947f4a29abdd8e9c4fda1a2b',
},
{
title: '海康外景球机28.136',
RegionID: '992984199da1489390174615fa6a9bc4',
ChannelID: '2582ef9c54c3480ebbfe1307536fbb6f',
id: '2582ef9c54c3480ebbfe1307536fbb6f',
key: '2582ef9c54c3480ebbfe1307536fbb6f',
parentId: '992984199da1489390174615fa6a9bc4',
},
{
title: '东北角朝南28.21',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '8efb9a9c40d74a1498dba03e769b7935',
key: '8efb9a9c40d74a1498dba03e769b7935',
id: '8efb9a9c40d74a1498dba03e769b7935',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '东北角朝西28.22',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '89abd4d82a8c46df8a355a9dc66f7040',
key: '89abd4d82a8c46df8a355a9dc66f7040',
id: '89abd4d82a8c46df8a355a9dc66f7040',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '产品部12.8',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '23bdb2b9455040f7a1a4b0e967ad30fd',
key: '23bdb2b9455040f7a1a4b0e967ad30fd',
id: '23bdb2b9455040f7a1a4b0e967ad30fd',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '会议室12.2',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: 'bddec760b3f94c429b008dddc65602c2',
key: 'bddec760b3f94c429b008dddc65602c2',
id: 'bddec760b3f94c429b008dddc65602c2',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '公司门口人脸12.27',
RegionID: 'a05bca905d3a42cca43471658179c2e9',
ChannelID: '59462100cde647c8a0f04190f8d5a115',
key: '59462100cde647c8a0f04190f8d5a115',
id: '59462100cde647c8a0f04190f8d5a115',
parentId: 'a05bca905d3a42cca43471658179c2e9',
},
{
title: '展厅12.3',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: 'b1e6170a4b044718927573e2e8007bd3',
key: 'b1e6170a4b044718927573e2e8007bd3',
id: 'b1e6170a4b044718927573e2e8007bd3',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '展厅门口人脸12.30',
RegionID: 'a05bca905d3a42cca43471658179c2e9',
ChannelID: 'd456986522a24b6fab29f99499f6b50b',
key: 'd456986522a24b6fab29f99499f6b50b',
id: 'd456986522a24b6fab29f99499f6b50b',
parentId: 'a05bca905d3a42cca43471658179c2e9',
},
{
title: '核研院内12.5',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '74440769267b48d38a696a78d3373ce1',
key: '74440769267b48d38a696a78d3373ce1',
id: '74440769267b48d38a696a78d3373ce1',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '活动室12.6',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: 'cd582a6a23d949c18f48d825b51dffe1',
key: 'cd582a6a23d949c18f48d825b51dffe1',
id: 'cd582a6a23d949c18f48d825b51dffe1',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '测试区人脸58.251',
RegionID: 'a05bca905d3a42cca43471658179c2e9',
ChannelID: '621455b297a5470ea2d5a2c465699b52',
key: '621455b297a5470ea2d5a2c465699b52',
id: '621455b297a5470ea2d5a2c465699b52',
parentId: 'a05bca905d3a42cca43471658179c2e9',
},
{
title: '测试组12.9',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: 'c863617f1554457f943c2f30184b56f9',
key: 'c863617f1554457f943c2f30184b56f9',
id: 'c863617f1554457f943c2f30184b56f9',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '海康28.27',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '93739b72a8dd46b9b6acc3d9476b8253',
key: '93739b72a8dd46b9b6acc3d9476b8253',
id: '93739b72a8dd46b9b6acc3d9476b8253',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '研发一部12.13',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '6617ab2ac3644c7593f9f1d80de7356e',
key: '6617ab2ac3644c7593f9f1d80de7356e',
id: '6617ab2ac3644c7593f9f1d80de7356e',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '研发二部12.4',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '2ee820680b524e52938b792e852e4597',
key: '2ee820680b524e52938b792e852e4597',
id: '2ee820680b524e52938b792e852e4597',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '系统集成部12.7',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '2d2a89f6fa99480faa63775e7f72a219',
key: '2d2a89f6fa99480faa63775e7f72a219',
id: '2d2a89f6fa99480faa63775e7f72a219',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '茶水间12.12',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '83d48bc5e70c40dfaacb7437f574968a',
key: '83d48bc5e70c40dfaacb7437f574968a',
id: '83d48bc5e70c40dfaacb7437f574968a',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '西南角朝东28.24',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: 'c49438602fd74f6095a83f00ed5917d3',
key: 'c49438602fd74f6095a83f00ed5917d3',
id: 'c49438602fd74f6095a83f00ed5917d3',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '西南角朝北28.23',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '26e070c7f90f4ef4854056b9c8dcf948',
key: '26e070c7f90f4ef4854056b9c8dcf948',
id: '26e070c7f90f4ef4854056b9c8dcf948',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
{
title: '领导办公室12.11',
RegionID: '1286f1b8f60f4bf283eecc6aadc1b51d',
ChannelID: '3210b0fa735247a0b207ad3237a495ca',
key: '3210b0fa735247a0b207ad3237a495ca',
id: '3210b0fa735247a0b207ad3237a495ca',
parentId: '1286f1b8f60f4bf283eecc6aadc1b51d',
},
]
//子找pid有的话,继续用pid找pid
let childrenIds = [
'df40dd86308e46848ad8962a53de31b7',
'd6b1aa1c980b486bac02337c27cfab4d',
]
const s1 = new Set()
function findParent(idx) {
arr.forEach(item => {
if (idx == item['id']) {
let pid = item['parentId']
s1.add(pid)
console.log(pid)
findParent(pid)
}
})
}
childrenIds.forEach(item => {
findParent(item)
})
const parent_ids = [...s1]
console.log(parent_ids)
console