How to include jquery.js in Grails?

后端 未结 10 2061
北海茫月
北海茫月 2021-02-05 06:50

I have a Grails 2.0.0 project that was created using grails create-app. In my HTML and GSP files, I\'m trying to include jquery.js. I\'ve tried all of

相关标签:
10条回答
  • 2021-02-05 07:18

    Currently, in 2015, all you have to do is add runtime ":jquery:1.11.1" to your BuildConfig.groovy, and that is all.

    0 讨论(0)
  • 2021-02-05 07:20

    I found (from the JQuery Plugin page) that in addition to using the <g:javascript library="jquery"/> tag, I had to add the plugin label explicitly to make the tag look like:

    <g:javascript library="jquery" plugin="jquery"/>

    Any idea why I had to use the plugin property?

    0 讨论(0)
  • 2021-02-05 07:27

    Steve after installing Jquery plugin thru grails install-plugin jquery you have to execute another grails command to download the jquery file in your app

    grails installJQuery
    

    This target downloads and installs jquery-1.7.1.js and jquery-1.7.1.min.js under web-app/js/jquery/

    0 讨论(0)
  • 2021-02-05 07:31

    I saw a good tutorial on that in icodeya. http://www.icodeya.com/2012/09/grails-different-ways-to-import.html

    you can either do this in your gsp:

    <g:javascript src="myscript.js"/ >
    

    OR you can do this in your Config.groovy:

    grails.resources.modules = {
    core{
    resource url:'/js/jQuery.js' 
    } 
    myScript { 
    resource url:'/js/myScript.js' 
    dependsOn 'core' 
    }
    }
    

    then, in your gsp, you can attach this:

    <r:require module="myScript" />
    
    0 讨论(0)
提交回复
热议问题