2017-03-31 55 views
1

我有這個類:誤差JsInteropt與GWT 2.8

package br.com.frame.client.teste; 
@JsType 
public class TesteJsInteropt { 

public int b = 5; 
} 

和我的頭的HTML代碼的JavaScript

<script type="text/javascript"> 
var a = new br.com.frame.client.teste.TesteJsInteropt(); 
alert(a.b); 
</script> 

在執行項目時,我在控制檯鉻收到此錯誤:

Uncaught ReferenceError: br is not defined

+0

通常它應該工作,你是從頭部還是從身體內部執行腳本?你是否嘗試過使用不同的命名空間或全局命名空間? –

回答

1

看起來像出口它不工作。您應該檢查是否啓用了-generateJsInteropExports標誌(如果此標誌未打開,導出將被忽略)。 另外,請注意GWT腳本加載的異步性質;您的上述代碼可能無法正常工作,因爲在執行new br.com.frame.client.teste.TesteJsInteropt();時,GWT應用程序未完全加載。

一個可能的解決方案是在加載完成時從您的應用程序入口點調用本地JS回調。