从 JSNI 方法中调用 Java 方法
Calling Java Method from within JSNI method
我正在尝试从我的 JSNI 方法中调用 java 方法。我没有收到任何类型的错误,但是 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");
}
}
它正在提醒 "NO DATA" 所以我知道我调用该方法的方式有问题。它不能是静态方法。
在 done
回调中你会丢失 this
(它现在会指向其他东西)。
您需要通过 bind
或局部变量 (var self = this
) 保存它。
我正在尝试从我的 JSNI 方法中调用 java 方法。我没有收到任何类型的错误,但是 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");
}
}
它正在提醒 "NO DATA" 所以我知道我调用该方法的方式有问题。它不能是静态方法。
在 done
回调中你会丢失 this
(它现在会指向其他东西)。
您需要通过 bind
或局部变量 (var self = this
) 保存它。