作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在围绕 JavaScript 库创建一个 GWT 包装器。 JavaScript 函数之一采用匿名对象作为其参数,例如:
obj.buildTabs({ hide: true, placeholder: 'placeholder' });
在 Java 方面,如何创建这种类型的 JavaScript 对象并将其传递给我的 native 实现?
目前,在 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 documentation的小剪辑:
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";
}-*/;
关于java - 如何将匿名 JavaScript 对象从 Java 传递到 GWT 中的 JavaScript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1457417/
我是一名优秀的程序员,十分优秀!