碰到循环树结构问题
需求是传入一个id,例如:B3OCM,通过循环得到只包含B3OCM的树结构:同时单板级和之前节点的不变
请注意! 此段树结构要寻找的 boardId 是数组内包多个id
const BoardMenus = [
{
key: '/neConfig/dvm/Spec/SystemConfiguration',
display: ['System Configuration', '配置管理'],
children: [
{
key: '/Subrack',
display: ['Subrack', '单板级'],
children: [
{
key: '/Configuration',
display: ['Configuration', '配置'],
children: [
{
key: '/WDM_Interface/WDMInterface', display: ['WDM Interface', 'WDM接口'],
boardId: ['B3OCM', 'B3PDU'],
type: '1'
},
{
key: '/Optical_Power_Management/OpticalPowerManagement', display: ['Optical Power Management', '光功率管理'],
boardId: ['B3PDU', 'B3OCM'],
type: '1'
},
{
key: '/Environment_Monitor', display: ['Environment Monitor', '环境监视配置'],
children: [
{
key: '/Environment_Monitor_Interface/Monitor_Interface', display: ['Environment Monitor Interface', '环境监视接口'],
boardId: ['B3PDU', 'B3OCM'],
type: '1'
}
]
},
{
key: '/Flexgrid_Monitor_Wavelength/FlexgridMonitorWavelength', display: ['Flexgrid Monitor Wavelength', 'Flexgrid监控器波长'],
boardId: ['B3LDU'],
type: '1'
},
{
key: '/Threshold_Management/ThresholdManagement', display: ['Threshold Management', '阈值管理'],
boardId: ['B3LDU'],
type: '1'
},
]
},
{
key: '/Alarm',
display: ['Board Alarm', '告警'],
children: [
{
key: '/Alarm_Severity_Auto/AlarmSeverityAuto', display: ['Alarm Severity Auto', '告警级别和自动上报设置'],
boardId: ['B3OCM', 'B3PDU'],
type: '2'
},
{ key: '/Alarm_Suppression/AlarmSuppression', display: ['Alarm Suppression', '告警抑制'] },
{ key: '/Alarm_Reversion/AlarmReversion', display: ['Alarm Reversion', '告警恢复'] },
]
},
{
key: '/Performance',
display: ['Subrack Performance', '性能'],
children: [
{
key: '/CurrentPerformance', display: ['Current Performance', '当前性能'],
boardId: ['B3OCM', 'B3LDU', 'B3PDU'],
type: '3'
},
],
},
],
},
]
}
]
如果传入上面树结构 并且传入id B3OCM
想要得到的结构是这样的
const Menus = [
{
key: '/neConfig/dvm/Spec/SystemConfiguration',
display: ['System Configuration', '配置管理'],
children: [
{
key: '/Subrack',
display: ['Subrack', '单板级'],
children: [
{
key: '/Configuration',
display: ['Configuration', '配置'],
type: '1',
children: [
{
key: '/WDM_Interface/WDMInterface', display: ['WDM Interface', 'WDM接口'],
boardId: ['B3OCM', 'B3PDU'],
type: '1'
},
{
key: '/Optical_Power_Management/OpticalPowerManagement', display: ['Optical Power Management', '光功率管理'],
boardId: ['B3PDU', 'B3OCM'],
type: '1'
},
{
key: '/Environment_Monitor', display: ['Environment Monitor', '环境监视配置'],
children: [
{
key: '/Environment_Monitor_Interface/Monitor_Interface', display: ['Environment Monitor Interface', '环境监视接口'],
boardId: ['B3PDU', 'B3OCM'],
type: '1'
}
]
},
]
},
{
key: '/Alarm',
display: ['Board Alarm', '告警'],
type: '2',
children: [
{
key: '/Alarm_Severity_Auto/AlarmSeverityAuto', display: ['Alarm Severity Auto', '告警级别和自动上报设置'],
boardId: ['B3OCM', 'B3PDU'],
type: '2'
},
]
},
{
key: '/Performance',
display: ['Subrack Performance', '性能'],
type: '3',
children: [
{
key: '/CurrentPerformance', display: ['Current Performance', '当前性能'],
boardId: ['B3OCM', 'B3LDU', 'B3PDU'],
type: '3'
},
],
},
],
},
]
}
]