我们将GWT2.3.0用于我们的web应用程序。我们已经开始将gwtquery用于我们的一些功能。
我想知道是否可以从gwtquery中调用js文件中的jquery函数。
发布于 2013-07-14 17:53:27
gwtquery,又名gQuery,是jquery for java的完全重写的实现。
gQuery的目标之一是拥有jquery的大部分特性(css选择器、dom操作、效果、promises、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的模块上完成的,主要目标是:设计师可以在不导入外部jquery.js的情况下,以html或ui.xml格式添加jquery代码,并且可以快速地将jquery插件移植到gquery中。
仅供参考:我在这里发布了一些benefits of using gquery作为gwt的补充。
https://stackoverflow.com/questions/17357372
复制相似问题