我正在尝试将一些js项目集成到我的vaadin应用程序中。我尝试了调用外部javascript代码的方法,只在一些简单/ javascript上成功了。 我尝试了NativeJs库 代码如下:
NativeJS nativeJScomponent = new NativeJS();
nativeJScomponent.setJavascript("alert('foo');");
nativeJScomponent.execute();
addComponent(nativeJScomponent);
然而,当我使用其他代码时,例如:
String jsCode = "<div /><script type=\"text/javascript\">var d = new Date();"
+ "var time = d.getHours();"
+ "if (time < 10) {document.write(\"<b>Good morning</b>\");}</script>";
NativeJS nativeJScomponent = new NativeJS();
nativeJScomponent.setJavascript(jsCode);
nativeJScomponent.execute();
addComponent(nativeJScomponent);
无法显示内容。
我还使用了customelayout和label来运行javascript。结果相同。
是否有一种方法将vaadin与js集成?