AbstractJavaScriptComponent Client To Server 函数调用
AbstractJavaScriptComponent Client To Server function call
我想从客户端调用服务器端函数 javascript。我不太确定我在这里做错了什么:
public class Test extends AbstractJavaScriptComponent {
public Test() {
addFunction("notifyServer", new JavaScriptFunction() {
@Override
public void call(JsonArray arguments) {
Notification.show("The client notified you!");
}
});
}
从 Javascript connector.js 我这样称呼它
function test(){
this.notifyServer();
notifyServer();
}
None 以上作品。每次我得到相同的堆栈跟踪
Uncaught TypeError: this.notifyServer is not a function
我解决了这个问题。我忘记了包装器的 this
仅在连接包装器的范围内可用。所以为了调用函数我必须这样做:
var serverObject;
window.demo_test_Test = function() {
serverObject = this;
}
function test(){
serverObject.notifyServer();
}
我想从客户端调用服务器端函数 javascript。我不太确定我在这里做错了什么:
public class Test extends AbstractJavaScriptComponent {
public Test() {
addFunction("notifyServer", new JavaScriptFunction() {
@Override
public void call(JsonArray arguments) {
Notification.show("The client notified you!");
}
});
}
从 Javascript connector.js 我这样称呼它
function test(){
this.notifyServer();
notifyServer();
}
None 以上作品。每次我得到相同的堆栈跟踪
Uncaught TypeError: this.notifyServer is not a function
我解决了这个问题。我忘记了包装器的 this
仅在连接包装器的范围内可用。所以为了调用函数我必须这样做:
var serverObject;
window.demo_test_Test = function() {
serverObject = this;
}
function test(){
serverObject.notifyServer();
}