从手写javascript调用实例方法的问题 [英] Issue with calling instance method from handwritten javascript
本文介绍了从手写javascript调用实例方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助解决以下代码中的错误(根据SO上提出的类似问题的答案):
public String javaMethod(String input){
returnit 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' 。
谢谢。
编辑:Huh,一小时后:发现我只需要 that。@ com ...
returned!
解决方案
后来:发现我只需要即。@ com ...
返回了!
桥接方法应该是:
public native void defineBridgeMethod()/ * - {
var that = this;
$ wnd.jsFunction = $ entry(function(msg){
return that。@ com.myclass.ClassName :: javaMethod(Ljava / lang / String;)(msg)
}) ;
} - * /;
Can anyone help with what is wrong in the code below(based on the answers to a similar question asked on 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)
});
}-*/;
The issue is that Javascript does not find jsFunction: alert(jsFunction) in Javascript code returns 'undefined'.
Thanks.
Edit: Huh, one hour later: figured out that I just needed to have that.@com...
returned!
解决方案
Huh, one hour later: figured out that I just needed to have that.@com...
returned!
The bridge method should be:
public native void defineBridgeMethod() /*-{
var that = this;
$wnd.jsFunction= $entry(function(msg) {
return that.@com.myclass.ClassName::javaMethod(Ljava/lang/String;)(msg)
});
}-*/;
这篇关于从手写javascript调用实例方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文