我需要桥接一个相当程序化的Javascript库,该库由一些.js文件组成,这些文件包含要从GWT调用的函数.
I need to bridge a fairly procedural Javascript library consisting of some .js files containing functions to call from GWT.
已经有了一个不错的实用程序GWT-Exporter,它的功能恰好相反(code.google/p/gwt-exporter/),我需要一种自动生成的GWT-Importer. javascript函数的Java包装器.
There's already a nice utility called GWT-Exporter that does exactly the opposite (code.google/p/gwt-exporter/), I would need a kind of GWT-Importer, that generated automatically .java wrappers of the javascript functions.
我知道这里的类型是一个问题,但是如果所有返回类型都变成JavaScriptObject或原语,我会很满足.
I'm aware type is an issue here, but I'd be content if all return types became JavaScriptObject or primitives.
JSNI似乎是这种方式,但是我想要一些可以自动创建类的东西,而不必通过JSNI手动绑定所有方法.
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.
推荐答案这听起来像是JSNI的工作.
This sounds like a job for JSNI.
code.google/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.
假设您有一个JavaScript库,希望在其中将函数foo()和bar(number)公开给GWT应用程序.您需要执行以下操作.
Say you have a JavaScript library where you want to have the functions foo() and bar(number) exposed to your GWT application. You'll want to do the following.
public final class LibraryName { public static native int foo() /*-{ $wnd.foo(); // Use $wnd instead of window in JSNI methods }-*/; public static native void bar(double number) /*-{ $wnd.bar(number) }-*/; }
有关JSNI的更深入的文章,请查看 googlewebtoolkit.blogspot/2008/07/getting-to-really-know-gwt-part-1-jsni.html .
更多推荐
有什么方法可以自动将Javascript库桥接到GWT?
发布评论