GWT의 Java에서 JavaScript로 익명의 JavaScript 객체를 어떻게 전달할 수 있습니까?

StackOverflow https://stackoverflow.com/questions/1457417

  •  12-09-2019
  •  | 
  •  

문제

JavaScript 라이브러리를 둘러싼 GWT 래퍼를 만들고 있습니다. JavaScript 함수 중 하나는 익명의 객체를 인수와 같은 것으로 간주합니다.

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

Java 쪽에서이 유형의 JavaScript 객체를 어떻게 만들고 내 기본 구현으로 전달합니까?

현재, 자바쪽에는 다음과 같습니다.

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

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

감사합니다. 감사합니다.

도움이 되었습니까?

해결책

어떤 매개 변수를 사용해야하는지 정확히 알고 있다면 다음을 수행 할 수 있습니다 (다음에 추가 새 라인을 제거하십시오. :)

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

The의 작은 클립 GWT 문서:

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";
  }-*/;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top