要构建HTML表,我使用直接DOM而不是预定义的Widget来设置thead和tbody.但是当我使用insertCell()方法插入一个单元格时,GWT会插入一个td元素,但是应该插入一个元素.
所以
TableElement table = Document.get().createTableElement();
TableSectionElement thead = table.createTHead();
TableRowElement headRow = thead.insertRow(-1);
headRow.insertCell(-1).setInnerText( "header1" );
Run Code Online (Sandbox Code Playgroud)
给
table/thead/tr/td
Run Code Online (Sandbox Code Playgroud)
但应该给
table/thead/tr/th
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?使用"old-school"DOM.createXXX() - 方法?
您可以手动创建和添加:
final TableCellElement th = Document.get().createTHElement();
th.setInnerText("i'm th!");
headRow.appendChild(th);
Run Code Online (Sandbox Code Playgroud)
你得到:
<table><thead><tr><td>header1</td><th>i'm th!</th></tr></thead></table>
Run Code Online (Sandbox Code Playgroud)