3

是否可以在 google web toolkit 中使用 jquery 插件?

有很多优秀的插件可用于各种 UI 小部件,例如日期/时间选择器、可搜索的下拉菜单等。在许多情况下,这些插件还带有自己的 css 样式。我希望能够使用这些插件并在我的 gwt 应用程序中获取它们的值。

4

2 回答 2

2

Yes .. you can use Javascript libs in GWT project. Simply import it's lib in your html file or GWT.xml. In your module.xml file as below..

<module rename-to='TestingProject'>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='test.Gwt.testingSample.client.TestingProjectEntry'/>
<inherits name="com.google.gwt.user.theme.standard.Standard" />
<source path='client'/>
<source path='shared'/>
<script src="/js/jquery-1.10.min.js"></script>
</module>

And test in your HTML file..

<body>
<center>
    <div id= "start"></div>
</center>
<script type="text/javascript">
     $(document).ready(function(){
     $("div#start").html("<font color = 'green' font-weight = 'bold' size = '12'>
                          Hello World !</font>");
});
</script>
<body>

Have a useful for you... !

于 2014-01-11T02:47:15.613 回答
2

根据经验,您有两种选择。

  1. 您可以使用 GwtQuery,它是大部分 jquery 的 gwt 本机版本。例如“$”实际上是一个静态java类。还有相当多的插件和插件具有很好的支持,例如用于拖放的 GwtQuery-DND。

http://code.google.com/p/gwtquery/

http://code.google.com/p/gwtquery-plugins/

  1. 另一种选择是为特定示例扮演自己的角色。如果你有一个你想要的特定 jquery 插件,而 GwtQuery 不适合你。您可以使用 gwt jsni 接口,它本质上允许您使用 java 本机接口调用本机 javascript。有很多插件以这种方式工作,例如 Gflot 和 gcodmirror(这是我现在使用的 wiki 编辑器的原生版本)。

JSNI 文档
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html

恕我直言,最好坚持使用 GwtQuery,因为 jquery 函数几乎可以在 GwtQuery 中逐字使用,并且您可以通过 gwt 编译器编译和优化代码获得额外的性能提升。

于 2014-01-10T22:54:31.587 回答