Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gwt 为什么我的@JsProperty没有在javascript中保留名称?_Gwt_Gwt Jsinterop - Fatal编程技术网

Gwt 为什么我的@JsProperty没有在javascript中保留名称?

Gwt 为什么我的@JsProperty没有在javascript中保留名称?,gwt,gwt-jsinterop,Gwt,Gwt Jsinterop,我有以下课程: @JsType public class Options { @JsProperty public boolean extractUrlsWithoutProtocol; public Options(boolean extractUrlsWithoutProtocol) { this.extractUrlsWithoutProtocol = extractUrlsWithoutProtocol; } } 现在我将它传递到一个

我有以下课程:

@JsType
public class Options {

    @JsProperty
    public boolean extractUrlsWithoutProtocol;

    public Options(boolean extractUrlsWithoutProtocol) {
        this.extractUrlsWithoutProtocol = extractUrlsWithoutProtocol;
    }
}
现在我将它传递到一个javascript方法中,当我使用开发人员工具进行检查时,我得到的属性名称是
extractUrlsWithoutProtocol\u 0\u g$

更重要的是,如果我删除@JsProperty注释,生成的代码就不会有任何更改

更新: 工作是什么

   public native void setExtractUrlsWithoutProtocol(boolean extractUrlsWIthoutProtocol_)
/*-{
    this.extractUrlsWithoutProtocol = extractUrlsWIthoutProtocol_;
}-*/;

编辑:我想你说的是GWT2.8。如果不是,我的答案不适用

我认为您在类上缺少了一个
@JsType
注释(对此不确定,但我认为GWT编译器可能会忽略未使用
@JsType
注释的类型,即使您确实有
@JsProperty
)。
另外,如果您的问题只是在生产模式下编译时出现的,请注意您需要一个特殊的编译器标志-
generateJsInteropExports
(默认情况下不支持JS互操作注释).

添加@JsType并确保启用-generateJsInteropExports没有任何区别将@JsType添加到我的原始问题中您的选项类如何?您能在输出JS中通过简单的文本搜索找到这个名称吗?我这样问是因为编译器会丢弃不符合某些限制的内容(并在输出中查找[WARN]语句)。本文档描述了这些限制:另外,您可能希望尝试使用无参数构造函数。文档中没有这样说,但它确实提到了在使用本机类型时,如果没有arg构造函数,您会遇到麻烦;我只是想知道你是怎么检查“它在工作”的。如果您只是包含.nocache.js并运行一个使用这些函数的脚本,您将获得某种竞争条件(因为.nocache.js异步加载特定于浏览器的排列)。我建议先用文本搜索你的输出JS。