简体   繁体   English

GWT中的JSNI方法

[英]JSNI method in GWT

Until I had this situation, it works : 在出现这种情况之前,它一直有效:

JS side: JS端:

jsMethod : function(){...}

GWT Java side: GWT Java端:

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 JS端

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

GWT Java side GWT Java端

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. 我将把参数从GWT传递给JS,然后返回一个String,但我不知道该怎么做。 Thank you . 谢谢 。

Just like Java. 就像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 您可以向本地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;
}-*/;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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