JS 将对象数组子项合并到父项

数据格式 

let arr = [{
            "parentNodeName": "车辆1",
            "parentNodeId": 1,
            "nodeName": "转向控制",
            "nodeId": 19,
            "baseLibraryId": "1663791170918150145",
            "childNodeList": [
                {
                    "id": 32,
                    "tmDfmeaId": "1663742185075671041",
                    "itemName": "方向盘",
                    "parentId": 19,
                    "nodeType": "零部件",
                    "nodeLevel": 3
                },
                {
                    "id": 3184,
                    "deleteFlag": 0,
                    "tmDfmeaId": "1663742185075671041",
                    "itemName": "方向电控",
                    "parentId": 19,
                    "nodeType": "零部件",
                    "nodeLevel": 3
                }
            ],
            "functionList": [
                {
                    "parentFunctionList": [
                        {
                            "nodeId": 15,
                            "nodeName": "方向电控",
                            "baseLibraryId": "1664533904775823361",
                            "sort": 9,
                            "rcList": [
                                {
                                    "id": 16,
                                    "deleteFlag": 0,
                                    "tmDfmeaId": "1663742185075671041",
                                    "itemName": "特性1",
                                    "parentId": 15,
                                    "nodeType": "要求特性",
                                    "nodeLevel": 3,
                                    "ancestors": "-1,1,15",
                                    "sort": null,
                                    "baseLibraryId": "1665622349820837889",
                                }
                            ]
                        },
                        {
                            "nodeId": 17,
                            "nodeName": "平稳",
                            "baseLibraryId": "1664536344296529921",
                            "sort": null,
                            "rcList": [
                                {
                                    "id": 18,
                                    "deleteFlag": 0,
                                    "tmDfmeaId": "1663742185075671041",
                                    "itemName": "大于100",
                                    "parentId": 17,
                                    "nodeType": "要求特性",
                                    "nodeLevel": 3,
                                    "ancestors": "-1,1,17"
                                }
                            ]
                        }
                    ],
                    "currentFunction": {
                        "nodeId": 20,
                        "nodeName": "安全行驶",
                        "baseLibraryId": "1664536400391151618",
                        "sort": null,
                        "rcList": [
                            {
                                "id": 21,
                                "tmDfmeaId": "1663742185075671041",
                                "itemName": "要求1",
                                "parentId": 20,
                                "nodeType": "要求特性",
                                "nodeLevel": 4
                            },
                            {
                                "id": 34,
                                "tmDfmeaId": "1663742185075671041",
                                "itemName": "要求2",
                                "parentId": 20,
                                "nodeType": "要求特性",
                                "nodeLevel": 4
                            }
                        ]
                    },
                    "lapseAnalyseOneList": [
                        {
                            "loseScoreList": [
                                {
                                    "nodeId": 22,
                                    "nodeName": "不舒服",
                                    "val": 5
                                },
                                {
                                    "nodeId": 3243,
                                    "nodeName": "方向偏移",
                                    "val": null
                                }
                            ],
                            "loseVal": 5,
                            "currentLoseNodeId": 23,
                            "currentLoseNodeName": "抖动",
                            "currentBaseLibraryId": "1664536782043455489",
                            "lapseAnalyseTowList": [
                                {
                                    "nodeId": 3188,
                                    "tmDfmeaId": null,
                                    "nodeName": "时速低于180",
                                    "baseLibraryId": "1664568460086378497",
                                    "childLosePcList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1",
                                            "tmBaseId": "2",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "提高人员的专业技术1",
                                            "measureName": "提高人员的专业技术"
                                        },
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "2",
                                            "tmBaseId": "4",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "工艺改进"
                                        }
                                    ],
                                    "childLosePcVal": 3,
                                    "childLoseDcList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1",
                                            "tmBaseId": "3",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "客户容易感知",
                                            "measureName": "客户容易感知",
                                            "val": 2,
                                            "type": "风险分析",
                                            "dcType": "FC",
                                            "showFlag": ""
                                        }
                                    ],
                                    "childLoseDcVal": 2,
                                    "riskAp": "L",
                                    "precautionList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1667061491058356226",
                                            "tmBaseId": "3",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "温度控制1",
                                            "measureName": "温度控制",
                                            "val": 7,
                                            "type": "优化",
                                            "dcType": null,
                                            "showFlag": "否"
                                        },
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1667062432369225730",
                                            "tmBaseId": "1667048322541826049",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "专业改进1",
                                            "measureName": "专业改进2",
                                            "showFlag": "否"
                                        }
                                    ],
                                    "detectionMeasureList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1667101920065912834",
                                            "tmBaseId": "1",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "中空板黑屏",
                                            "showFlag": "否"
                                        },
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "2",
                                            "tmBaseId": "2",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "参数需要调整",
                                            "measureName": "参数需要调整",
                                            "val": 3,
                                            "type": "优化",
                                            "dcType": "FC",
                                            "showFlag": ""
                                        }
                                    ],
                                    "optimize": {
                                        "id": "1",
                                        "parentTreeId": 23,
                                        "tmTreeId": 3188,
                                        "leader": "admin",
                                        "leaderId": "admin",
                                        "planCompleteDate": "2023-06-02 08:44:43",
                                        "realityCompleteDate": "2023-06-07 08:44:48",
                                        "feVal": 5
                                    },
                                    "evidenceBasedMeasureList": [

                                    ],
                                    "optimizeFrequency": 7,
                                    "optimizeDetectability": null,
                                    "optimizeAp": null
                                },
                                {
                                    "nodeId": 3189,
                                    "tmDfmeaId": null,
                                    "nodeName": "时速低于160",
                                    "baseLibraryId": "1664537921791041537",
                                    "childLosePcList": null,
                                    "childLosePcVal": null,
                                    "childLoseDcList": null,
                                    "childLoseDcVal": null,
                                    "riskAp": null,
                                    "precautionList": null,
                                    "detectionMeasureList": null,
                                    "optimize": {
                                        "id": "1667102480089382913",
                                        "version": 1,
                                        "deleteFlag": 0
                                    },
                                    "evidenceBasedMeasureList": null,
                                    "optimizeFrequency": null,
                                    "optimizeDetectability": null,
                                    "optimizeAp": null
                                },
                                {
                                    "nodeId": 3191,
                                    "tmDfmeaId": null,
                                    "nodeName": "老化",
                                    "baseLibraryId": "1666028294438768641"
                                }
                            ]
                        },
                        {
                            "loseScoreList": [
                                {
                                    "nodeId": 24,
                                    "nodeName": "方向偏移",
                                    "val": null
                                }
                            ],
                            "loseVal": null,
                            "currentLoseNodeId": 3106,
                            "currentLoseNodeName": "有异响",
                            "currentBaseLibraryId": "1664538404198916097",
                            "lapseAnalyseTowList": [
                                {
                                    "nodeId": 3188,
                                    "tmDfmeaId": null,
                                    "nodeName": "时速低于180",
                                    "baseLibraryId": "1664568460086378497",
                                    "childLosePcList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1",
                                            "tmBaseId": "2",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "提高人员的专业技术1",
                                            "measureName": "提高人员的专业技术"
                                        },
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "2",
                                            "tmBaseId": "4",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "工艺改进",
                                            "measureName": "工艺改进"
                                        }
                                    ],
                                    "childLosePcVal": 3,
                                    "childLoseDcList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1",
                                            "tmBaseId": "3",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "客户容易感知",
                                            "measureName": "客户容易感知"
                                        }
                                    ],
                                    "childLoseDcVal": 2,
                                    "riskAp": null,
                                    "precautionList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1667061491058356226",
                                            "tmBaseId": "3",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "温度控制1"
                                        },
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1667062432369225730",
                                            "tmBaseId": "1667048322541826049",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "专业改进1",
                                            "measureName": "专业改进2"
                                        }
                                    ],
                                    "detectionMeasureList": [
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "1667101920065912834",
                                            "tmBaseId": "1",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "中空板黑屏"
                                        },
                                        {
                                            "tmDfmeaId": "1663742185075671041",
                                            "dcPcId": "2",
                                            "tmBaseId": "2",
                                            "parentTreeId": 23,
                                            "tmTreeId": 3188,
                                            "name": "参数需要调整",
                                            "measureName": "参数需要调整"
                                        }
                                    ],
                                    "optimize": {
                                        "id": "1",
                                        "version": null,
                                        "deleteFlag": 0,
                                        "state": null,
                                        "parentTreeId": 23,
                                        "tmTreeId": 3188,
                                        "leader": "admin",
                                        "leaderId": "admin",
                                        "planCompleteDate": "2023-06-02 08:44:43",
                                        "realityCompleteDate": "2023-06-07 08:44:48",
                                        "feVal": 5
                                    },
                                    "evidenceBasedMeasureList": [

                                    ],
                                    "optimizeFrequency": 7,
                                    "optimizeDetectability": null,
                                    "optimizeAp": null
                                },
                                {
                                    "nodeId": 3189,
                                    "tmDfmeaId": null,
                                    "nodeName": "时速低于160",
                                    "baseLibraryId": "1664537921791041537",
                                    "childLosePcList": null,
                                    "childLosePcVal": null,
                                    "childLoseDcList": null,
                                    "childLoseDcVal": null,
                                    "riskAp": null,
                                    "precautionList": null,
                                    "detectionMeasureList": null,
                                    "optimize": {
                                        "id": "1667102480089382913",
                                        "version": 1,
                                        "deleteFlag": 0
                                    },
                                    "evidenceBasedMeasureList": null,
                                    "optimizeFrequency": null,
                                    "optimizeDetectability": null,
                                    "optimizeAp": null
                                }
                            ]
                        }
                    ]
                },
                {
                    "parentFunctionList": [

                    ],
                    "currentFunction": {
                        "nodeId": 3182,
                        "nodeName": "安全",
                        "baseLibraryId": "1666022393384390657",
                        "sort": null,
                        "rcList": [
                            {
                                "id": 3183,
                                "deleteFlag": 0,
                                "tmDfmeaId": "1663742185075671041",
                                "itemName": "粘稠2",
                                "parentId": 3182,
                                "nodeType": "要求特性",
                                "nodeLevel": 4,
                                "ancestors": "-1,1,19,3182",
                                "baseLibraryId": "9",
                            }
                        ]
                    },
                    "lapseAnalyseOneList": [

                    ]
                }
            ]
        }]
const ret = arr.flatMap(({ functionList, ...other }) => {
  return functionList.map(item => {
    return { functionList: [item], ...item, ...other }
    })
  })
const ret1 = ret.flatMap(({ lapseAnalyseOneList, ...other }) => {
  return lapseAnalyseOneList.map(item => {
    return { lapseAnalyseOneList: [item], ...item, ...other }
    })
})
const ret2 = ret1.flatMap(({ lapseAnalyseTowList, ...other }) => {
  return lapseAnalyseTowList.map(item => {
     return { lapseAnalyseTowList: [item], ...item, ...other }
     })
})
console.log(ret2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想散在风中

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值