[英]Calling Java Method from within JSNI method
I am trying to call a java method from within my JSNI method. 我试图从我的JSNI方法中调用Java方法。 I am not getting any type of error but the Window.alert()
never gets called. 我没有收到任何类型的错误,但是Window.alert()
从未被调用。
package com.mywebsite.myapp.client;
public class MyApp implements EntryPoint(){
/// Other stuff....
public native void getToServer(String trainerName)/*-{
$wnd.$.get( "http://testdastuff.dev/trainerstats", { trainer: trainerName} )
.fail(function() {
$wnd.console.log("error");
})
.done(function( data ) {
if(data == "noData"){
alert("NO DATA");
this.@com.mywebsite.myapp.client.MyApp::testJSNI()();
}
});
}-*/;
public void testJSNI(){
Window.alert("Working");
}
}
It is alerting "NO DATA" so i know something is wrong with the way I am calling the method. 它正在警告“无数据”,因此我知道我调用该方法的方式有问题。 It cant be a static method. 它不能是静态方法。
Inside of the done
callback you will have lost this
(it will point to something else now). 在done
回调中,您将失去this
(它现在指向其他位置)。
You need to preserve it via bind
or a local variable ( var self = this
). 您需要通过bind
或局部变量( var self = this
)保留它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.