有什么方法可以自动将Javascript库桥接到GWT?

编程入门 行业动态 更新时间:2024-10-27 09:44:41
本文介绍了有什么方法可以自动将Javascript库桥接到GWT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要桥接一个相当程序化的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.

  • 将JavaScript库放在您的war目录中. (如果是外部托管,则不需要.)
  • 通过在主机页面上添加<script>标记来包含脚本
  • 创建实用程序类
  • Put the JavaScript library in your war directory. (Not needed if externally hosted.)
  • Include the script by adding a <script> tag to your host page
  • Create the utility class
  • 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?

    本文发布于:2023-10-07 17:18:17,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1470004.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:有什么   可以自动   桥接   方法   GWT

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!