任何人都可以帮助解决下面代码中的错误(基于SO上提出的类似问题的答案):
public String javaMethod(String input) {
return "it works";
}
public native void defineBridgeMethod() /*-{
var that = this;
$wnd.jsFunction= $entry(function(msg) {
that.@com.myclass.ClassName::javaMethod(Ljava/lang/String;)(msg)
});
}-*/;
问题是Javascript找不到jsFunction:Javascript代码中的alert(jsFunction)返回'undefined'。
感谢。
编辑:嗯,一小时后:发现我只需要让that.@com...
返回!
答案 0 :(得分:2)
that.@com...
回来!
桥接方法应该是:
public native void defineBridgeMethod() /*-{
var that = this;
$wnd.jsFunction= $entry(function(msg) {
return that.@com.myclass.ClassName::javaMethod(Ljava/lang/String;)(msg)
});
}-*/;