Issue with calling instance method from handwritten javascript

偶尔善良 提交于 2019-12-25 04:15:19

问题


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!


回答1:


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)
        });
}-*/;


来源:https://stackoverflow.com/questions/9676960/issue-with-calling-instance-method-from-handwritten-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!