好吧,这真的很烦人,因为我确信GWT应该支持我想做的事情.我已经问了两次我在网上搜索但我找不到解决问题的办法.
我想要做的是从服务器加载一个文本文件,如下所示:
<!-- linear_regression.txt -->
<h1>Linear Regression</h1>
Welcome to this chapter. Here, have a graph:
<div id="whatever"></div>
Alright, now have some math stuff:
Run Code Online (Sandbox Code Playgroud)
并将Widget- 在我的情况下一个折线图 - 放入div <div id="whatever">.我试过几件事......
在onSuccess()RPC 的方法中我想做类似的事情:
public void onSuccess(String result) {
HTMLPanel tmp = new HTMLPanel(result);
Element el = tmp.getElementById("whatever");
el.appendChild(new LineChart().asWidget().getElement());
contentRoot.add(tmp);
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我的结果如下:
<div id="whatever">
<!-- Here I want the chart to be placed but all I get is this: -->
<div></div>
</div>
Run Code Online (Sandbox Code Playgroud)
另一种方法如下:
HTMLPanel tmp = new HTMLPanel(result);
contentHome.add(tmp);
Element el = RootPanel.get("whatever").getElement();
el.appendChild(new LineChart().asWidget().getElement());
Run Code Online (Sandbox Code Playgroud)
但在这里我得到了一个未被捕获的例外:
java.lang.AssertionError: A widget that has an existing parent widget
may not be added to the detach list
at com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(RootPanel.java:136)
at com.google.gwt.user.client.ui.RootPanel.get(RootPanel.java:211)
at ew.client.layout.MainLayout$1.onSuccess(MainLayout.java:95)
at ew.client.layout.MainLayout$1.onSuccess(MainLayout.java:1)
...
Run Code Online (Sandbox Code Playgroud)
我真的厌倦了这个问题.有谁知道我怎么能解决这个问题?
包裹div在里面HTLMPanel
LineChart lineChart = new LineChart();
HTMLPanel panel = new HTMLPanel(result);
panel.add(lineChart, "whatever");
Run Code Online (Sandbox Code Playgroud)