2015-03-19 79 views
0

我无法设法让我的Grails 2.4.4应用程序中的JQuery Datepicker工作。不管有没有jQuery UI插件,它都会失败。是不是因为它使用jquery 1.11将UI组件集成到最新的jquery插件中?如何添加日期选择器?grails 2.4.4 jquery datepicker

我有这样的代码:

BuildConfig.groovy:

... 
plugins { 
     // plugins for the build system only 
     build ":tomcat:7.0.55" 

     // plugins for the compile step 
     compile ":scaffolding:2.1.2" 
     compile ':cache:1.1.8' 
     compile ":asset-pipeline:2.1.3" 
     compile ":mail:1.0.7" 

     build ':tomcat:7.0.54' 

     // plugins needed at runtime but not for compilation 
     runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18" 
     runtime ":jquery:1.11.1" 
     //compile ":jquery-ui:1.10.4" 

的application.js

//= require jquery 
//= require_tree . 
//= require_self 

if (typeof jQuery !== 'undefined') { 
    (function($) { 
     $('#spinner').ajaxStart(function() { 
      $(this).fadeIn(); 
     }).ajaxStop(function() { 
      $(this).fadeOut(); 
     }); 
    })(jQuery); 
} 

create.gsp

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
     <meta name="layout" content="main" /> 
     <title>Create</title>    
    </head> 
    <body>  
     <g:javascript library="jquery" plugin="jquery"/> 
<%--  <jq:resource bundle="ui" components="datepicker" /> Gives a nullpointer exception!!!--%> 
     <script type="text/javascript"> 
     $(document).ready(function() 
     { 
      $("#install").datepicker({dateFormat: 'yyyy/mm/dd'}); 
     }) 
     </script> 

     <div class="body"> 
... 
<input name="install" id="install" value="${fieldValue(bean:blaBlubInstance,field:'install')}"/> 

回答

0

你必须取消对jQuery的-ui插件在插件部分 并在下一行添加到您的application.js

//= require js/jquery-ui-1.10.4.custom.min 

,也许你想在你appliaction.css的默认主题

*= require themes/ui-lightness/jquery-ui-1.10.4.custom.min 

我希望这有助于。

+0

没有抱歉。我在chrome中得到这个错误:'未捕获的TypeError:undefined不是函数' at this line: '$(“#install”)。datepicker({dateFormat:'yyyy/mm/dd'});' – BioBier 2015-03-23 14:06:02

+0

@ BioBer,你是否将你的application.js和application.css包含在主布局中? – 2015-03-24 14:52:28