Grails: Javascript files in the views folder

I would like to split my views in Grails into 2 .gsp files and a .js file so that I get a clearer Javascript separation from my views. So here is an example:

views/index.gsp
views/index.js
views/home/index.jsp
views/home/index.js

But when I just add the index.js script link as follows:

<script src="index.js" type="text/javascript"></script>

all i get is 404.

Does anyone know how to deal with this?

A big advantage would be the ability to use view data in the index.js file to get the desired content.

Matthias

+3
source share
4 answers

, , JS ( ) GSP grails-app/views/. , , - URL GSP, :

"/javascript/home/index"(view:'/home/index.js')

URL JS- grails-app/views/home/index.js.gsp ( .gsp), grails JS. JS ,

<%@ page contentType="text/javascript"%>

GSP.

, createLink , .

, , . JS ( ), , , JS. . ..

+4

2:

Grails .

, javascript grails-app/views web-app/js.

$PROJECT/scripts/Events.groovy. PackagingEnd , web.xml.

eventPackagingEnd = {  ->
     // for each js file under grails-app/views move to web-app/js
}

, javascript , , :

grails-app/views/view1/index.js → webapp/js/view1/index.js

, Grails , -.

javascript, .


Javascript web-app/js.

, <g:javascript src="index.js" />.

0

, Grails - . ().

web-inf, , , , .

Javascript , , , javascript ! , , . ShrinkSafe - .

0

, js /

...

  • create js and rename it with myjs.gsp (use "") iniside _myjs.gsp type you js
... write you js here ...
  1. inside you gsp (ex: index.gsp, view.gsp etc.) enter this tag to load js

0
source

Source: https://habr.com/ru/post/1710924/


All Articles