GWT 包括来自模块清单的外部 javascript 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4431675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 11:24:46  来源:igfitidea点击:

GWT including external javascript file from module's manifest

javascriptgwtmanifest

提问by Giorgio

So I read the documentation about including an external Javascript file directly in the module manifest yourApplication.gwt.xml (http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html)

所以我阅读了关于在模块清单 yourApplication.gwt.xml (http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html) 中直接包含外部 Javascript 文件的文档

I have this javascript file called iscroll.js and stored in the war/ folder of the GWT project.

我有一个名为 iscroll.js 的 javascript 文件并存储在 GWT 项目的 war/ 文件夹中。

I added the line to the module's manifest of my GWT application:

我将这一行添加到我的 GWT 应用程序的模块清单中:

<script src="iscroll.js"/>

Then from the onModuleLoad()method I call this native JSNI method:

然后从onModuleLoad()我调用这个原生 JSNI 方法的方法:

private native void initJavascript() /*-{
  $wnd.myScroll = new iScroll('jokeWrapperLabel');
}-*/;

Then when I run the code in the browser I keep getting "iScroll is undefined".

然后当我在浏览器中运行代码时,我不断收到“iScroll is undefined”。

Any idea what am I doing wrong?

知道我做错了什么吗?

This is the output of the "iScroll is undefined error"

这是“iScroll is undefined error”的输出

18:32:41.780 [ERROR] [jollyjokesprogwt] Unable to load module entry point class com.wanderlust.jollyjokespro.gwt.client.JollyJokesProGWT (see associated exception for details)
com.google.gwt.core.client.JavaScriptException: (ReferenceError): iScroll is not defined
 stack: ReferenceError: iScroll is not defined
    at [object Object].<anonymous> (unknown source)
    at __gwt_jsInvoke (http://127.0.0.1:8888/jollyjokesprogwt/hosted.html?jollyjokesprogwt:76:35)
    at http://127.0.0.1:8888/jollyjokesprogwt/hosted.html?jollyjokesprogwt:280:16
    at C (http://127.0.0.1:8888/jollyjokesprogwt/jollyjokesprogwt.nocache.js:2:148)
    at http://127.0.0.1:8888/jollyjokesprogwt/jollyjokesprogwt.nocache.js:8:593
 type: not_defined
 arguments: iScroll
 __gwt_ObjectId: 91
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    at com.wanderlust.jollyjokespro.gwt.client.JollyJokesProGWT.initJavascript(JollyJokesProGWT.java)
    at com.wanderlust.jollyjokespro.gwt.client.JollyJokesProGWT.onModuleLoad(JollyJokesProGWT.java:228)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:183)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Unknown Source)

回答by Hilbrand Bouwkamp

You need to place the JavaScript file in a public folder, see this stackoverflow answer on how that works: gwt and javascript filesand the call to iScroll(..must be $wnd.iScroll(...

您需要将 JavaScript 文件放在公共文件夹中,请参阅有关其工作原理的 stackoverflow 答案:gwt 和 javascript 文件以及对iScroll(..must的调用$wnd.iScroll(..