如何從JSNI調用外部JS?gwt/jsni-從外部JS傳遞字符串到Java
例如:
//Some external JS code
...
this.onFeatureClick = function(event) {
...
var name = "Batman";
passToJava(name); //Invoke java method and pass String name
};
我試過這個位置:
public void onModuleLoad() {
...
nativeVariableName(); //Call native method
}
public static void passToJava(String name) {
System.out.println(name);
}
public native String nativeVariableName() /*-{
$wnd.passToJava = function(name) {
@com.google.myproject.webinterface.client.MyWebInterface::passToJava(Ljava/lang/String;)(name);
}; }-*/;
我甚至不知道從JavaScript調用工作。 謝謝。
看一看GWT的文檔,第一部分介紹瞭如何從JavaScript發送一個變量到Java:http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#writing – milan 2012-01-08 21:00:53
公衆static void alert(String msg)/ * - { $ wnd.alert(msg); } - * /; – milan 2012-01-08 21:00:59