【问题标题】:grails 2.4.4 jquery datepickergrails 2.4.4 jquery datepicker
【发布时间】:2015-03-19 08:12:58
【问题描述】:

我无法让 JQuery Datepicker 在我的 Grails 2.4.4 应用程序中工作。 无论有没有 jquery-UI 插件,它都会失败。最新的jquery插件中集成的UI组件不是这样吗,因为它使用的是jquery 1.11?如何添加日期选择器?

我有这个代码:

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"

应用程序.js

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

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

创建.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')}"/>

【问题讨论】:

    标签: jquery grails datepicker


    【解决方案1】:

    您必须在插件部分取消注释 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
    

    我希望这会有所帮助。

    【讨论】:

    • 不抱歉。我在 chrome 中收到此错误:Uncaught TypeError: undefined is not a function 在这一行:$("#install").datepicker({dateFormat: 'yyyy/mm/dd'});
    • @BioBer,你的 application.js 和 application.css 是否包含在主布局中?
    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 2015-02-05
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多