update(table):增加解析表格容错性
This commit is contained in:
parent
a880592b5b
commit
28e32b4dae
|
@ -126,7 +126,7 @@ class ControllBar extends EventEmitter2 implements ControllBarInterface {
|
|||
);
|
||||
});
|
||||
const trs = table.rows;
|
||||
end = end || trs.length;
|
||||
end = end || trs?.length || 0;
|
||||
const rowBars = this.rowsHeader?.find(Template.ROWS_HEADER_ITEM_CLASS);
|
||||
for (let i = start; i < end; i++) {
|
||||
rowBars?.eq(i)?.css('height', `${trs[i].offsetHeight}px`);
|
||||
|
|
|
@ -45,7 +45,7 @@ class Helper implements HelperInterface {
|
|||
let model: Array<Array<TableModelCol | TableModelEmptyCol>> = [];
|
||||
const tableElement = table.get<HTMLTableElement>()!;
|
||||
const rows = tableElement.rows;
|
||||
const rowCount = rows.length;
|
||||
const rowCount = rows?.length || 0;
|
||||
|
||||
for (let r = 0; r < rowCount; r++) {
|
||||
const tr = rows[r];
|
||||
|
@ -312,7 +312,7 @@ class Helper implements HelperInterface {
|
|||
fixNumberTr(table: NodeInterface) {
|
||||
const tableElement = table.get<HTMLTableElement>()!;
|
||||
const rows = tableElement.rows;
|
||||
const rowCount = rows.length;
|
||||
const rowCount = rows?.length || 0;
|
||||
let colCounts: Array<number> = [];
|
||||
let firstColCount: number = 0; // 第一列的单元格个数
|
||||
let cellCounts = []; // 每行单元格个数
|
||||
|
|
|
@ -891,7 +891,17 @@ class TableComponent<V extends TableValue = TableValue>
|
|||
// 第一次渲染
|
||||
if (!value) return 'Error value';
|
||||
if (value.html) {
|
||||
const model = this.helper.getTableModel($(value.html));
|
||||
let table = $(value.html);
|
||||
if (table.name !== 'table') {
|
||||
table = table.toArray().find((child) => child.name === 'table');
|
||||
if (!table) {
|
||||
value.html = `<table><tr><td>${value.html}</td></tr></table>`;
|
||||
table = $(value.html);
|
||||
} else {
|
||||
value.html = table.get<Element>().outerHTML;
|
||||
}
|
||||
}
|
||||
const model = this.helper.getTableModel(table);
|
||||
value.rows = model.rows;
|
||||
value.cols = model.cols;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue