(function (cols) {
//1.横向处理 设置每一行X
for (var row = 0; row < cols.length; row++) {
var currow = cols[row];
for (var col = 0; col < currow.length; col++) {
if (col == 0) {
currow[col]["X"] = 1;
} else {
currow[col]["X"] = currow[col - 1].X + (currow[col - 1].colspan || 1);
}
currow[col]["Y"] = row;
}
}
//2.纵向处理 纠正错误的X
for (var r = 0; r < cols.length; r++) {
if (r == 0) { continue; }
var cr = cols[r];
for (var c = 0; c < cr.length; c++) {
//上行对应td
var curtd = cr[c];
var lasttd = null;
//查找X相等的Cell
for (var or = r - 1; or >= 0; or--) {
var lastRow = cols[or];
for (var oc = 0; oc < lastRow.length; oc++) {
lasttd = lastRow[oc];
if (lasttd.X == curtd.X) {
if ((lasttd.rowspan || 1) > (curtd.Y - lasttd.Y)) {
//当列后以及后面的列都加
for (var f = c ; f < cr.length; f++) {
cr[f].X += (lasttd.colspan || 1);
}
//继续对当前行判断
c -= 1;
}
break;
}
}
}
}
}
})(meargeColumns);