如何从浏览器控制台访问GWT的JsInterop导出类型? [英] How to access GWT's JsInterop exported types from browser console?

查看:100
本文介绍了如何从浏览器控制台访问GWT的JsInterop导出类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行GWT应用程序,我想使用JsInterop快速测试某些内容.

I'm running a GWT application and I want to test something quickly with JsInterop.

具体地说,我导出了enum:

package com.mypackage.test

@JsType
enum MyEnum {
    A,
    B,
    C;
}

我想在编写任何代码之前检查是否可以正确访问它.

And I wanna check if I can access it properly before writing any code.

文档显示如下内容:

var aClass = new com.gwt.example.MyClass('World');

但是Window中未定义com.那么如何在编写代码之前从控制台访问JsInterop进行测试呢?

But com is not defined in Window. So how can I access JsInterop from console to test things before writing code?

推荐答案

您是否记得将-generateJsInteropExports标志传递给编译器(以及Super Dev Mode)?没有它,GWT将不会导出类型,因为这会增加输出大小.

Did you remember to pass the -generateJsInteropExports flag to the compiler (and to Super Dev Mode)? Without it, GWT will not export types, since that increases output size.

此外,该程序包看起来并不像您期望在GWT项目中看到的通常结构(即,其中的client对应于您的GWT模块)-您是否记得从中引用了此程序包. gwt.xml文件?

Also, that package doesn't look like the usual structure you expect to see in a GWT project (i.e. a client somewhere in there, corresponding to your GWT module) - did you remember to reference this package from your .gwt.xml file?

这也可能是public-JsInterop代码默认不显示不可见成员(因为它们不是公共成员,因此不假定在其他地方使用).我不确定这是否适用于类型,或者仅适用于成员.

It is also possible that this should be public - the JsInterop code defaults to not showing non-visible members (since they aren't public, so aren't assumed to be consumed elsewhere). I'm not sure if this applies to types, or just members.

最后,请注意,用JsType标记Java enum并不能使它们在JS中有意义-在指定的包中将存在MyEnum类型,并且每个静态成员都会存在,但是它们将是不透明的JS对象,而不是字符串或可以轻松与之交互的其他对象,除非您还对该类的方法添加了其他jsinterop注释. J2CL支持@JsEnum,虽然可以将它们全部自动转换为数字常量,但是尚未将其移植到GWT2.

Finally, be aware that marking a Java enum with JsType doesn't magically make them make sense in JS - there will be a MyEnum type at the specified package, and each of those static members will be present, but they will be opaque JS objects, not strings or something else you can easily interact with, unless you also add other jsinterop annotations on the methods in that class. J2CL supports a @JsEnum which will turn them all into numeric constants automatically though, but this hasn't yet been ported to GWT2.

这篇关于如何从浏览器控制台访问GWT的JsInterop导出类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆