我需要桥接一个相当程序化的 Javascript 库,该库由一些 .js 文件组成,其中包含从 GWT 调用的函数。
已经有一个名为 GWT-Exporter 的不错的实用程序,它的作用恰恰相反(http://code.google.com/p/gwt-exporter/),我需要一种 GWT-Importer,它自动生成 .java 包装器JavaScript 函数。
我知道类型是这里的一个问题,但如果所有返回类型都变成 JavaScriptObject 或基元,我会感到满意。
JSNI 似乎是这样,但我想要自动创建类的东西,而不必通过 JSNI 手动绑定所有方法。
I need to bridge a fairly procedural Javascript library consisting of some .js files containing functions to call from GWT.
There's already a nice utility called GWT-Exporter that does exactly the opposite (http://code.google.com/p/gwt-exporter/), I would need a kind of GWT-Importer, that generated automatically .java wrappers of the javascript functions.
I'm aware type is an issue here, but I'd be content if all return types became JavaScriptObject or primitives.
JSNI seems to be the way, but I'd want something that created the classes automatically instead of having to manually bind via JSNI all of the methods.
发布评论
评论(1)
这听起来像是 JSNI 的工作。
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html
如果您知道要调用哪些函数,那么设置一个包含表示相关函数的静态方法的实用程序类就相当容易了。
假设您有一个 JavaScript 库,您希望将函数
foo()
和bar(number)
暴露给您的 GWT 应用程序。您需要执行以下操作。war
目录中。 (如果外部托管则不需要。)标记添加到您的主机页来包含脚本
创建实用
有关 JSNI 的更深入文章,请查看 http://googlewebtoolkit.blogspot.com/2008/07/getting-to-really-know-gwt-part-1-jsni.html。
This sounds like a job for JSNI.
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html
If you know which functions you would like to call, it's fairly easy to set up a single utility class that contains static methods representing the functions in question.
Say you have a JavaScript library where you want to have the functions
foo()
andbar(number)
exposed to your GWT application. You'll want to do the following.war
directory. (Not needed if externally hosted.)<script>
tag to your host pageFor a more in-depth article about JSNI, take a look at http://googlewebtoolkit.blogspot.com/2008/07/getting-to-really-know-gwt-part-1-jsni.html.