如何在gwt Uibinder中使用JavaScript [英] How to use JavaScript with gwt Uibinder

查看:98
本文介绍了如何在gwt Uibinder中使用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我用GWT编写的应用程序中执行JavaScript。
这是以普通HTML工作的代码:

 < html> 
< head>
< / head>

< body>
< ul>
< li>< / li>
< li>< / li>
< li>< / li>
< li>< / li>
< li>< / li>
< / ul>
< script src =jquery.js>< / script>
< script src =jquery.roundabout.js>< / script>
< script>
$(document).ready(function(){
$('ul')。roundabout();
});
< / script>
< / body>
< / html>

(假设 jquery.js 和<$ )

我有一个 somePresenter code>(with someView.java someView.ui.xml ),我希望上面的代码工作在 someView.ui.xml



我复制上面的代码粘贴到XML(除< html> 标签我有< g:HTMLPanel> 标签)
,但JavaScript没有似乎会被执行(我所看到的只是列表,因为它应该在脚本之前)。



如何让它工作?

相关问题:我可以使用GQuery来处理这个
(类似于:GQuery。$()。getScript(jquery.roundabout.js)来加载外部js脚本)吗?



提前致谢

解决方案

c>< script> 在UiBinder中,并期望看到它的加载和执行原因与你相同不要在JS中的 innerHTML 中放置< script> > HTMLPanel 和UiBinder将使用 innerHTML 内置)。



如果您需要动态加载脚本,查看 ScriptInjector

  ScriptInjector.fromUrl(GWT.getModuleBaseURL()+'jquery.js')。inject(); 

我想GQuery使用 ScriptInjector


I want to execute JavaScript in my application which is written with GWT. This is the code that works in a regular HTML:

<html>
  <head>
  </head>

  <body>
    <ul>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>
    <script src="jquery.js"></script>
    <script src="jquery.roundabout.js"></script>
    <script>
      $(document).ready(function() {
          $('ul').roundabout();
      });
    </script>
  </body>
</html>

(Assume jquery.js and jquery.roundabout.js are in the same folder.)

I have a somePresenter (with someView.java and someView.ui.xml) and I want the above code to work in the someView.ui.xml.

I copy pasted the above code to the XML (except for <html> tag I have <g:HTMLPanel> tag) but the JavaScript doesn't seem to be executed (all I see is the list as it should be before the script).

How can I make it work?

Related question: can I some how use GQuery for this (something like: GQuery.$().getScript(jquery.roundabout.js) to load external js script)?

Thanks in advance

解决方案

You can't put a <script> in UiBinder and expect to see it loaded and executed for the same reasons you cannot put a <script> in a innerHTML in JS with the same expactations (simply because HTMLPanel and UiBinder will use innerHTML under-the-hood).

If you need to load scripts dynamically, have a look at the ScriptInjector:

ScriptInjector.fromUrl(GWT.getModuleBaseURL() + 'jquery.js').inject();

I suppose GQuery uses ScriptInjector or works similarly.

这篇关于如何在gwt Uibinder中使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆