Grails 1.3.3,JQuery 1.6.1.1,main.gsp

时间:2011-06-15 19:28:51

标签: jquery-plugins grails

我已将grails.views.javascript.library =“jquery”添加到config.groovy,安装了插件并运行“grails InstallJQuery”将.js文件导入/web-app/js.

如果我将<g:javascript library="jquery" plugin="jquery"/>添加到我的视图中,代码将按预期工作:

search.gsp
...
<g:javascript library="jquery" plugin="jquery"/>
...
  <div id="searchBox">
    <g:remoteField
      name="q"
      update="peoplePanel"
      paramName="q"
      url="[controller:'user', action:'search']" />
  </div>
  <div id="peoplePanel">    <!-- ajax response will be placed in this div -->
  </div>

resulting code:
...
<script type="text/javascript" src="/find-people/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.js"></script>
...
  <div id="searchBox">
    <input type="text" name="q" value="" onkeyup="jQuery.ajax({type:'POST',data:'q='+this.value, url:'/find-people/user/search',success:function(data,textStatus){jQuery('#peoplePanel').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});" />
  </div>
  <div id="peoplePanel">    <!-- ajax response will be placed in this div -->
  </div>

如果我从视图中删除<g:javascript library="jquery" plugin="jquery"/>,请将<meta name="layout" content="main">添加到视图中并将<g:javascript library="jquery" plugin="jquery"/>添加到main.gsp,生成的ajax代码不同,搜索字段中的自动完成功能为no更长的作品:

main.gsp
...
<g:javascript library="jquery" plugin="jquery"/>
...

search.gsp
...
<meta name="layout" content="main">
...
  <div id="searchBox">
    <g:remoteField
      name="q"
      update="peoplePanel"
      paramName="q"
      url="[controller:'user', action:'search']" />
  </div>
  <div id="peoplePanel">    <!-- ajax response will be placed in this div -->
  </div>

resulting code:
...
<script type="text/javascript" src="/find-people/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.js"></script>
...
  <div id="searchBox">
    <input type="text" name="q" value="" onkeyup="new Ajax.Updater('peoplePanel','/find-people/user/search',{asynchronous:true,evalScripts:true,parameters:'q='+this.value});" />
  </div>
  <div id="peoplePanel">    <!-- ajax response will be placed in this div -->
  </div>

我无法控制如何处理封面。不使用layout / main.gsp似乎是唯一的选择,但有明显的缺点。

1 个答案:

答案 0 :(得分:1)

似乎默认的Prototype优先于jQuery。 尝试删除原型。

p.s如果您正在使用

,则无需运行grails InstallJQuery

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

运行<g:javascript library="jquery" />

后,您应该使用grails InstallJQuery