方法封装
function merge(data, key) {
const newData = data.map((item, index) => {
const filterData = data.filter(ele => {
return item[key] == ele[key]
})
const index_ = data.findIndex(ele => {
return item[key] == ele[key]
})
if (index == index_) {
item.rowspan = filterData.length
} else {
item.rowspan = 0
}
return item
})
return newData
}
function arraySpanMethod({ row, columnIndex }) {
if (columnIndex === 0) {
return {
rowspan: row.rowspan,
colspan: 1
}
}
}
方法调用
const tableData = merge(props.listdata, "STNM")
<el-table :data="tableData":span-method="arraySpanMethod" ></el-table>
网友评论