[英]How can I pass an anonymous JavaScript object from Java to JavaScript in GWT?
我正在圍繞JavaScript庫創建GWT包裝器。 JavaScript函數之一將匿名對象作為其參數,例如:
obj.buildTabs({ hide: true, placeholder: 'placeholder' });
在Java方面,如何創建這種JavaScript對象並將其傳遞給本機實現?
目前,在Java方面,我有:
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()()});
}-*/;
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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.