简体   繁体   中英

JSNI method in GWT

Until I had this situation, it works :

JS side:

jsMethod : function(){...}

GWT Java side:

public static native void javaMethod(JavaScriptObject obj)  /*-{
    var test = null;
    test = ... ;
    test.jsMethod();    
}-*/;

The problem is when I try to do something like this

JS side

jsMethod : function(a, b){... return string}

GWT Java side

String a = 'yes'
String b = 'no'

public static native void javaMethod(JavaScriptObject obj)  /*-{
    var test = null;
    test = ... ;

    var testString = null;
    testString = test.jsMethod(a, b);   
}-*/;

I would be to pass parameter from GWT to JS and then returns a String but I dont' know how to make it. Thank you .

Just like Java. Return a String.

public static native String javaMethod(JavaScriptObject obj)  /*-{
    var test = null;
    test = ... ;

    var testString = null;
    testString = test.jsMethod(a, b); 
    return testString;  
}-*/;

You can add parameters to the native JavaMethod

public static native String javaMethod(JavaScriptObject obj, String a, String b)  /*-{
    var test = null;
    test = ... ;

    var testString = null;
    testString = test.jsMethod(a, b);
    return testString;
}-*/;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM