【问题标题】:Grails 1.3.3, JQuery 1.6.1.1, main.gspGrails 1.3.3、JQuery 1.6.1.1、main.gsp
【发布时间】:2011-06-15 19:28:51
【问题描述】:

我已将 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>

如果我从视图中删除&lt;g:javascript library="jquery" plugin="jquery"/&gt;,将&lt;meta name="layout" content="main"&gt; 添加到视图并将&lt;g:javascript library="jquery" plugin="jquery"/&gt; 添加到main.gsp,生成的ajax 代码不同并且搜索字段中的自动完成不再起作用:

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 似乎是唯一的选择,但也有明显的缺点。

【问题讨论】:

    标签: jquery-plugins grails


    【解决方案1】:

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

    p.s 如果您正在使用,则不必运行 grails InstallJQuery

    &lt;g:javascript library="jquery" plugin="jquery"/&gt;

    你应该在运行grails InstallJQuery之后使用&lt;g:javascript library="jquery" /&gt;

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2011-06-10
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 2014-04-16
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多