GWT JSNI是否支持回调? [英] Does GWT JSNI support callbacks?

查看:81
本文介绍了GWT JSNI是否支持回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用Web SQL本地存储的GWT应用( http://dev.w3.org/html5/webdatabase/). 问题是Web SQL API使用回调函数作为 争论.

I am building a GWT app that uses Web SQL Local Storage ( http://dev.w3.org/html5/webdatabase/ ). The problem is that the Web SQL API uses callback functions as arguments.

是否可以将"Java"回调传递给JSNI?

Is it possible to pass "Java" callbacks to JSNI?

推荐答案

是的,它确实:

private static native void doThingWithCallback() /*-{
  var self = this;
  var callbackFn = $entry(function(val) {
    self.@com.your.package.AClass.aMethod(Ljava/lang/String;)(val);
  });
  $wnd.someApiThatTakesACallback(callbackFn);
}-*/;

两件事要记住:

  1. $entry()提醒GWT使用调试器时要跟踪代码.
  2. var self = this在函数内部保留对this的引用-否则this将是函数本身...
  1. $entry() reminds GWT to keep track of the code when using the debugger.
  2. var self = this keeps the reference to this inside the function -- otherwise this will be the function itself...

这篇关于GWT JSNI是否支持回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆