分解单元格合并的行
for (let i = td_row.rowIndex + 1; i < td_row.rowIndex + init_rowspan; i++) { // 向下一行开始插入td
// 计算插入位置,
let in_index
for (let a = 0; a < tb.rows[i].cells.length; a++) {
const td_rc = JSON.parse(tb.rows[i].cells[a].getAttribute('td_rc') as string)
if(td_rc && td_rc.maxc == init_col - 1){ // init_col 单元格的 实际列号,非index
in_index = tb.rows[i].cells[a].cellIndex +1
if (i == 4) { console.log('第4行 所有 td',tb.rows[i].cells)}
// 看控制台打印, 问题在这 行,得到index 为2 的 td, 而不是index 1 的 td
if (i == 4) { console.log('第4行 cells[1]元素',tb.rows[i].cells[1])} // 这是啥原因造成的?
if (i == 4) { console.log('第4行 cells[1]元素的 index',tb.rows[i].cells[1].cellIndex)}
break
}else if(td_rc && td_rc.c == init_maxc + 1){
in_index = tb.rows[i].cells[a].cellIndex
break
}
}
nextTick(() => {
// console.log('3运行到这了',i, in_index)
new_td = tb.rows[i].insertCell(in_index)
new_td.setAttribute('td_rc', `{"r":${i},"c":${in_index},"maxc":${in_index},"maxr":${i}}`)
new_td.innerText = '新行'
})
}
}
另外控制台,两个 length 也不一样,一个4 一个5