简体   繁体   English

无法在GWT中使用外部javascript

[英]unable to use external javascript in GWT

I want to use goJS with GWT. 我想在GWT中使用goJS。 I downloaded GOJS javascript and put it in the sampleproject folder under war where sampleproject.nocache.js and sampleproject.devmode.js is present. 我下载了GOJS javascript,并将其放在存在sampleproject.nocache.js和sampleproject.devmode.js的战争中的sampleproject文件夹中。 In sampleproject.html i added 在sampleproject.html中,我添加了

<script type="text/javascript" language="javascript" src="sampleproject/go.js"> 
</script>

In one of the view i used 在我使用的一种观点中

public static native void initGo() /*-{
    var $$ = go.GraphObject.make;
}-*/;

when i call this function , exception is thrown: 当我调用此函数时,会引发异常:

com.google.gwt.event.shared.UmbrellaException: Exception caught: (ReferenceError) @com.amazon.ops.client.OpsMenuView::initGo()([]): go is not defined. com.google.gwt.event.shared.UmbrellaException:捕获到异常:(ReferenceError)@ com.amazon.ops.client.OpsMenuView :: initGo()([]):go未定义。

Can anyone please help me with this? 谁能帮我这个忙吗?

Try prefixing the js call with $wnd. 尝试在js调用前面加上$wnd. , eg: ,例如:

var $$ = $wnd.go.GraphObject.make;

As explained here , GWT runs in a nested frame and you must use $wnd to refer to the top level window. 正如解释在这里 ,GWT运行在一个嵌套的框架,您必须使用$wnd指顶层窗口。

Make sure that you put this statement: 确保您输入以下语句:

<script type="text/javascript" language="javascript" src="sampleproject/go.js"> 
</script>

before <script src="sampleproject.nocache.js"> statement. <script src="sampleproject.nocache.js">语句之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM