How to include jquery.js in Grails?

后端 未结 10 2292
北海茫月
北海茫月 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:06

    Update for Grails 2.3 This might help troubleshoot the configuration of jQuery so it can be available from your gsp pages.

    1. First of all if you run the grails install-plugin jquery command it will fail with the 'install-plugin' obsolete message: enter image description here

    So most likely you already have it configured in your BuildConfig.groovy like this (note is runtime, not compile):

    plugins {
        // ... some other plugins here ...
        runtime ":jquery:1:11:1"
    }
    
    1. If you are using Eclipse, do a File search for jquery and see if you already have the files: enter image description here

    2. Confirm that your js directory is not empty, it is located inside the web-app directory. If js has no files or directories then just copy them from what you got in in step 2: enter image description here

    3. As mentioned before, the combination of these two lines seems to work (at the top of your gsp pages):

    enter image description here

    If jQuery is not the very first javascript library to load you might have problems. Check your layouts/main.gsp file if you have one. You might need to add jquery to all your pages just so it is at the very top of your html source.

    Hope that helps.

    Note: At the time of this posting (April 2015) Grails 3.0 has been released and it appears to be incompatible with Grails 2.X projects in the way they are configured. Hopefully it will be better documented to avoid the issues with 2.X.

提交回复
热议问题