2012-09-20 25 views
0

我想添加jquery庫到我的項目之後添加tipsy.js以及用工具提示做一個「插件」。沒有GQuery的jquery + gwt

的事情是,我已經加js在我gwt.xml文件但我仍然不能稱之爲「$」將jQuery

我gwt.xml文件是:

<module ... 
    <!-- jquery and plugins --> 
    <script src="/javascripts/jquery.min.js"></script> 
    <script src="/javascripts/tipsy.js"></script> 

和在JS調用的方法是:

public static native void allClassName(String className) /*-{ 
    $wnd.jQuery(className).tipsy({trigger: 'focus', gravity: 'w'}); 
}-*/; 

但我永諾得到這個錯誤:在java.lang.Th

read.run(Thread.java:680) 引起:com.google.gwt.core.client.JavaScriptException:(TypeError):Object [object Window]在com.google.gwt.dev上沒有方法'jQuery' .shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 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 netagenda.ui.gwt.client.gin.ClientGinjectorImpl.com $ gwtplatform $ mvp $ client $ HandlerContainerImpl_automaticBind_methodInjection_ _ _(ClientGinjectorImpl.java) at netagenda.ui.gwt.client.gin.ClientGinjectorImpl.memberInject_Key $ type $ netagenda $ ui $ gwt $ client $ pages $ backend $ customers $ presenter $ CustomerPagePresenter $ _annotation $$ none $$ (ClientGinjectorImpl.java:1395) at netagenda.ui.gwt.client.gin.ClientGinjectorImpl.create_Key $ type $ netagenda $ ui $ gwt $ client $ pages $ backend $ customers $ presenter $ CustomerPagePresenter $ _annotation $$ none $$( ClientGinjectorImpl.java:1408) at netagenda.ui.gwt.client.gin.ClientGinjectorImpl.get_Key $ type $ netagenda $ ui $ gwt $ client $ pages $ backend $ customers $ presenter $ CustomerPagePresenter $ _annotation $$ none $$(ClientGinjectorImpl .java:1421) at netagenda.ui.gwt.client.gin.ClientGinjectorImpl.access $ 12(ClientGinjectorImpl.java:1419) at netagenda.ui.gwt.client.gin.ClientGinjectorImpl $ 13 $ 1.onSuccess(ClientGin jectorImpl.java:2768) 在com.google.gwt.core.client.GWT.runAsync(GWT.java:255)

+0

1.接受大家的提問一些答案。 2.當您編寫jQuery(className)而不是$ wnd.jQuery(className)時會發生什麼? –

+0

我得到這個錯誤 引起:com.google。gwt.core.client.JavaScriptException:(ReferenceError):jQuery沒有定義可能是我沒有正確添加庫jQuery的?但是在gwt.xml中添加腳本就足夠了,是真的嗎? –

+0

那麼,這幾乎可以解決你的問題,出於某種原因,jQuery庫沒有正確地在您嘗試使用它的函數中正確拾取。 –

回答

2

我已經解決了添加文件到像Home.html文件中:

<!-- jquery and plugins --> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script> 
    <script src="http://onehackoranother.com/projects/jquery/tipsy/javascripts/jquery.tipsy.js"></script> 

後這是我的方法使用GWT呼叫插件:

public static native void allClassName(String className) /*-{ 
     $wnd.jQuery(className).tipsy({trigger: 'focus', gravity: 'w'}); 
    }-*/; 
0

在GWT的最後一個版本中,你不能在模塊中添加JavaScript文件,你需要在你的入口點,以注入 這樣:

在您的入口點類:

ScriptInjector.fromString(PluginClientBundle.INSTANCE.plugins().getText()) 
     .setWindow(ScriptInjector.TOP_WINDOW) 
     .inject(); 

你的包類

public interface PluginClientBundle extends ClientBundle { 
    static final PluginClientBundle INSTANCE = GWT.create(PluginClientBundle.class); 

    @Source("resource/js/jquery-plugin.min.js") 
    TextResource plugins(); 
}