合作联系微信: w6668263      合作联系电话:177-9238-7426     

tree数据结构来计算跨行

const data = [{
    'id': '92838232090121',
    'psId': '8832878989329',
    'psName': '无锡火电厂01',
    'mpId': '7928810012121',
    'mpName': 'SBR法工艺流程',
    'area': 90.1,
    'equip': [{
            'equipId': '1212121',
            'equipName': '脱硫泵',
            'pollutantCodes': [{
                'pollutantype': 'g2008',
                'pollutantName': 'SO2',
                'producfactor': '12.12',
                'effictRate': '50'
            }]
        },
        {
            'equipId': '1212121',
            'equipName': '脱硫泵',
            'pollutantCodes': [{
                    'pollutantype': 'g2008',
                    'pollutantName': 'SO2',
                    'producfactor': '12.12',
                    'effictRate': '50'
                },
                {
                    'pollutantype': 'g2003',
                    'pollutantName': 'NO',
                    'producfactor': '13.12',
                    'effictRate': '60'
                }
            ]
        },
        {
            'equipId': '1212132',
            'equipName': '脱硫泵AA',
            'pollutantCodes': [{
                    'pollutantype': 'g2008',
                    'pollutantName': 'SO2',
                    'producfactor': '12.12',
                    'effictRate': '50'
                },
                {
                    'pollutantype': 'g2003',
                    'pollutantName': 'NO',
                    'producfactor': '13.12',
                    'effictRate': '60'
                },
                {
                    'pollutantype': 'g2005',
                    'pollutantName': 'CO',
                    'producfactor': '12.12',
                    'effictRate': '89'
                }
            ]
        }
    ]
}]

const deepGetColspan = (node) => {
    let rowspan = 0
    const children = node.equip || node.pollutantCodes
    node.rospan = 1
    if (children && children.length > 0) {
        children.forEach(child => {
            rowspan += deepGetColspan(child)
        })
        node.rospan = rowspan
    }
    return node.rospan
}

data.forEach(node => {
    deepGetColspan(node)
})

 

posted on 2020-08-11 17:11  草率的龙果果  阅读(241)  评论(0编辑  收藏  举报

导航