从 GWT 2.3 升级到 2.4 导致我的一个扩展 CellTable 的类出现客户端异常。功能并没有损失,但异常(exception)的是持续的开发烦恼。
com.google.gwt.core.client.JavaScriptException: (TypeError): this.insertBefore 不是函数
我已经确定了导致此问题的行,但直到稍后渲染表时才会引发异常。在行更改处理程序中,当 CellTable 中没有行时,MyCellTable 会删除标题元素。下面是一些在 2.4 中导致异常但在 2.3 中不会导致异常的示例代码。
CellTable<String> table = new CellTable<String>();
table.addColumn(new TextColumn<String>() {
@Override
public String getValue(String object) {
return object;
}
}, "Col");
List<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
table.setRowData(list);
NodeList<Element> els = table.getElement().getElementsByTagName("THEAD");
if (els.getLength() == 0) {
return;
}
final Element e = els.getItem(0);
e.removeFromParent();
降级到 GWT 2.3 可以解决该问题。我尝试调用 headerElement.setAttribute("style", "display: none") 而不是删除该元素,但这看起来不一样(它仍然保留了一些像素)。我知道创建一个 CellTable 然后删除它的一部分可能是一个不好的做法。
GWT 2.4 中是否存在任何可能导致此问题的已知更改?有人能想到解决方法吗?
最佳答案
您可以通过在单元格表的“thead”css 属性上使用 CSS 属性:“display: none”来实现相同的结果(隐藏标题)。
方法如下:
<强>1。创建一个 css 文件,其中包含以下条目:
全局样式.css:
.hiddenHeader thead {
display: none;
}
<强>2。将此文件添加到客户端资源包:
GlobalResources.java
public interface GlobalResources extends ClientBundle {
public static final GlobalResources RESOURCE = GWT.create(GlobalResources.class);
@Source("GlobalStyles.css")
GlobalStylesheet styles();
}
<强>3。在代码中,您可以在没有行时以编程方式设置样式:
cellTable.addStyleName(GlobalResources.RESOURCE.styles().hiddenHeader());
要删除样式,请调用以下命令:
cellTable.removeStyleName(GlobalResources.RESOURCE.styles().hiddenHeader());
完成!
关于java - GWT 2.4 CellTable 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7611980/