数据先循环
for (var i = 0; i < this.list.length; i++) {
if (i === 0) {
this.spanArr.push(1)
this.pos = 0
} else {
// 判断当前元素与上一个元素是否相同(第1和第2列)
if (this.list[i].shipmentNo === this.list[i - 1].shipmentNo) {
this.spanArr[this.pos] += 1
this.spanArr.push(0)
} else {
this.spanArr.push(1)
this.pos = i
}
}
}
调用合并方法
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex < 9) {
合并前9行
const _row = this.spanArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
} else if (columnIndex === 3) {
const _row = this.contentSpanArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
},