grails 2.0包含资源的简单方法?

Ray*_*Ray 12 grails grails-2.0

我一直在从Grails 2.0的Grails 1.3.7迁移中解决各种资源包含问题,可能还不了解一些事情.

首先,做什么

<g:javascript library="application" />
Run Code Online (Sandbox Code Playgroud)

做?(这是在Grails 1.3.7中提供的默认main.gsp中).

其次,为了在我的应用程序中包含jquery,我可以这么做

<r:require module='jquery' />
<r:layoutResources />
Run Code Online (Sandbox Code Playgroud)

在我的主sitemesh页面的顶部

 <g:layoutHead /> 
    ...
 <g:layoutBody />
Run Code Online (Sandbox Code Playgroud)

和"完成它",使用

<r:layoutResources />
Run Code Online (Sandbox Code Playgroud)

之后的第二次

 <g:layoutBody />
Run Code Online (Sandbox Code Playgroud)

谢谢

Ste*_*eve 12

是的,我最初也在努力解决这个问题.

所以首先<g:javascript library="application" />指的是config/*.Resources.groovy文件中定义的模块(默认是config/ApplicationResources.groovy),里面有你命名的模块,例如:

modules = {
    application {
          resource url: 'js/jquery/jquery-ui-1.8.15.custom.min.js', disposition: 'head'
  }
}
Run Code Online (Sandbox Code Playgroud)

其次通过示例Grails2 main.gsp(这里减少很多):

 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><g:layoutTitle default="Grails"/></title>
    <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css">
    <link rel="stylesheet" href="${resource(dir: 'css', file: 'mobile.css')}" type="text/css">

    <link rel="stylesheet" href="${resource(dir: 'css/redmond', file: 'jquery-ui-1.8.15.custom.css')}" type="text/css">

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

    <r:require module="application"/>
    <r:layoutResources/>

</head>

<body>
    <g:layoutBody/>
    <r:layoutResources/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

希望能让你朝着正确的方向前进