Frage

Ich bin ein GWT-Wrapper um eine JavaScript-Bibliothek zu erstellen. Einer der JavaScript-Funktionen übernimmt ein anonymes Objekt als Argument z.

obj.buildTabs({ hide: true, placeholder: 'placeholder' });

Auf der Java-Seite, wie kann ich diese Art von JavaScript-Objekt erstellen und an meine native Implementierung übergeben?

Im Moment auf der Java-Seite habe ich:

public void buildTabs(TabConfiguration config) {
   // ?
}

private native void buildTabs(?) /*-{
        $wnd.NAMESPACE.lib.buildTabs(?);
}-*/;

Alle Hinweise dankbar, danke.

War es hilfreich?

Lösung

, wenn Sie genau wissen, welche Parameter verwendet werden sollen, können Sie die folgende (entfernen zusätzliche neue Linien nach ::)

private native void buildTabs(TabConfiguration config) /*-{
        $wnd.NAMESPACE.lib.buildTabs({hide: 
                config.@com.yournamehere.TabConfiguration::
                getHide()(), 
                placeholder: 
                config.@com.yournamehere.TabConfiguration::
                getPlaceholder()()});
}-*/;

ein kleiner Clip aus dem GWT Dokumentation :

public native void bar(JSNIExample x, String s) /*-{
    // Call instance method instanceFoo() on this
    this.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);

    // Call instance method instanceFoo() on x
    x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);

    // Call static method staticFoo()
    @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);

    // Read instance field on this
    var val = this.@com.google.gwt.examples.JSNIExample::myInstanceField;

    // Write instance field on x
    x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + " and stuff";

    // Read static field (no qualifier)
    @com.google.gwt.examples.JSNIExample::myStaticField = val + " and stuff";
  }-*/;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top