【问题标题】:JSNI callback to GWT function from Foundation - not being firedJSNI 从 Foundation 回调到 GWT 函数 - 未被触发
【发布时间】:2014-02-18 13:49:56
【问题描述】:

我再次与 JSNI 回调问题作斗争(请参阅我的发帖历史记录)。我正在为 Foundation Joyride(游览)构建一个包装器。游览运行正常,但“postRideCallback”(游览结束后调用)不会触发。如果我使用(接近)相同的语法从控制台调用游览,回调会触发。

这是有效的,从控制台:

$(document).foundation( 
    { joyride : 
        { post_ride_callback : function() 
            { window.alert('hello world'); } 
    } 
}).foundation('joyride', 'start')

这是相关的 GWT 代码;调用 start() 会运行游览,但不会调用回调。

public void start() {
    __native_start(endTour(this), anotherFunction(this));
}

public native static void __native_start(JavaScriptObject endTour, JavaScriptObject  
anotherFunction) /*-{
    anotherFunction(); // this runs

    $wnd.$($doc).foundation(
        { joyride :
            { postRideCallback: function() // this does not run
                { 
                  anotherFunction(); 
                  endTour(); 
                }
            }
        }
    ).foundation('joyride', 'start');
}-*/;

public static native JavaScriptObject endTour(Tour tour) /*-{
    return tour == null ? null : $entry(function() {
        tour.@io.myapp.client.ui.widgets.foundation.Tour::tourHasEnded()()
    });
}-*/;

public static native JavaScriptObject anotherFunction(Tour tour) /*-{
    return tour == null ? null : $entry(function() {
        tour.@io.myapp.client.ui.widgets.foundation.Tour::callbackSuccess()()
    });
}-*/;

public void callbackSuccess() {
    Window.alert("hello yes");
}

编辑 - 在这里要清楚:

a) 请注意,第一次调用 anotherFunction() 有效。在运行游览之前,它会弹出一个带有“hello yes”的警报。 b) 如果我将 postStepCallback 函数的主体替换为 window.alert('hello world');$wnd.alert('hello world'),则不会发生任何事情。所以我认为这与 GWT 引用本身没有任何关系(尽管我认为它们似乎是错误的)。

EDIT2 - 好的,对 Tomasz 进行了一些修改(并删除了 $entry 样板作为实验)。新行为 - 开发模式控制台中的堆栈跟踪(代码后):

public void start() {
    __native_start(endTour(this), anotherFunction(this));
}

public native static void __native_start(JavaScriptObject endTour, JavaScriptObject         anotherFunction) /*-{
    anotherFunction();

    $wnd.$($doc).foundation(
        { joyride :
            { postRideCallback: function() { endTour(); } }
        }
    ).foundation('joyride', 'start');
}-*/;

public static native JavaScriptObject endTour(Tour tour) /*-{
    return tour.@io.myapp.client.ui.widgets.foundation.Tour::tourHasEnded();
}-*/;

public static native JavaScriptObject anotherFunction(Tour tour) /*-{
    return tour.@io.myapp.client.ui.widgets.foundation.Tour::callbackSuccess();
}-*/;

public void tourHasEnded() {
    Window.alert("hello double");
}

public void callbackSuccess() {
    Window.alert("hello yes");
}

堆栈跟踪:

com.google.gwt.core.client.JavaScriptException: (String) : Invoking an instance method on a null instance   
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  
at com.google.gwt.dev.shell.ModuleSpace.createJavaScriptException(ModuleSpace.java:80)  
at com.google.gwt.dev.shell.ModuleSpace.createJavaScriptException(ModuleSpace.java:64)  
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:60)   
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)    
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)    
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)    
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)    
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)  
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299)  
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)    
at io.myapp.client.ui.widgets.foundation.Tour.__native_start(Tour.java)

【问题讨论】:

    标签: gwt zurb-foundation jsni


    【解决方案1】:

    答案:我在 GWT 代码中使用的是旧的(Foundation 4)驼峰式大小写,而不是下划线分隔的选项名称。在控制台中,我发现下划线是正确的昨晚深夜,但是当我今天早上用 GWT 尝试这个时忘记了这一点。呃。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多