0

我们将 GWT 2.3.0 用于我们的 Web 应用程序。我们已经开始将 gwtquery 用于我们的一些功能。

我想知道是否可以在 gwtquery 的 js 文件中调用 jquery 函数。

4

1 回答 1

0

gwtquery aka gQuery 是一个完全重写的 jquery for java 实现。

gQuery 的目标之一是拥有 jquery 的大部分功能(css 选择器、dom 操作、效果、promise、ajax 等),但不必导入外部 jquery.js 库,受益于 gwt 的所有优点(优化,性能,死代码删除等)。

因此,gQuery 和 jQuery 不能共享插件,所以如果您在应用程序中使用 jquery.js,因为您使用的是 jquery-plugin,您仍然需要在项目中导入 jquery。

总之,如果你想使用jquery的语法但在gwt中,你不需要导入jquery而不是从java调用外部js方法。

import static com.google.gwt.query.client.GQuery.*;

public void onModuleLoad() {
    //add a click handler on the button
    $("button").click(new Function(){
      public void f() {
        //display the text with effects and animate its background color
        $("#text").as(Effects)
          .clipDown()
          .animate("backgroundColor: 'yellow'", 500)
          .delay(1000)
          .animate("backgroundColor: '#fff'", 1500);
      }
    });
}

否则,如果你不使用 gqueyr 并且想在你的页面中导入 jquery,为了从 gwt 调用一些方法,你必须编写 jsni 方法:

native void enhanceMyButton() /*-{
    $("button").click(function() {
        //display the text with effects and animate its background color
        $("#text").as(Effects)
          .clipDown()
          .animate("backgroundColor: 'yellow'", 500)
          .delay(1000)
          .animate("backgroundColor: '#fff'", 1500);
    });
}-*/;

最后,在 gwtquery 中,我们正在努力公开 gquery 方法以集成纯 jquery 代码。这项工作是在我们称为jsQuery的模块上完成的,主要目标是:设计人员可以在 html 或 ui.xml 中添加 jquery 代码,而无需导入外部 jquery.js,它可以是一种快速移植 jquery 的方法gquery 的插件。

仅供参考:我在这里发布了使用 gquery作为 gwt 补充的一些好处

于 2013-07-14T09:53:27.373 回答