同理
如果对第二列进行合并的话copy一下第一个方法,让值赋给第二个数组就可以
java
// 合并方法
mergeCells({ row, column , rowIndex, columnIndex }) {
debugger;
if (columnIndex === 1) {
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
console.log(_col, '_col');
return {
rowspan: _row, //行
colspan: _col //列
};
}else if (columnIndex ===2){
const _row = this.spanSecondArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
console.log(_col, '_col');
return {
rowspan: _row, //行
colspan: _col //列
};
}
},
getSpanFirstArr(data) {
this.spanArr = [];
for (var i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr.push(1);
this.pos = 0;
} else {
// 判断当前元素与上一个元素是否相同
if (data[i].orgName === data[i - 1].orgName && data[i].orgName) {
this.spanArr[this.pos] += 1;
this.spanArr.push(0);
} else {
this.spanArr.push(1);
this.pos = i;
}
}
}
},
// 对类型的合并
getSpanSecondArr(data) {
this.spanSecondArr = [];
for (var i = 0; i < data.length; i++) {
if (i === 0) {
this.spanSecondArr.push(1);
this.pos = 0;
} else {
// 判断当前元素与上一个元素是否相同
if (data[i].wgareaType === data[i - 1].wgareaType && data[i].wgareaType) {
this.spanSecondArr[this.pos] += 1;
this.spanSecondArr.push(0);
} else {
this.spanSecondArr.push(1);
this.pos = i;
}
}
}
},```