GwtQuery - 从外部js文件调用函数

时间:2013-06-28 04:48:22

标签: gwtquery

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

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

1 个答案:

答案 0 :(得分:0)

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

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

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

总之,如果你想在jwt中使用jquery的语法,你不需要导入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。

仅供参考:我在这里发布了一些benefits of using gquery作为gwt的补充

相关问题