Datepicker jqueryui不适用于require.js和backbone.js

时间:2013-07-15 13:50:55

标签: jquery-ui backbone.js datepicker requirejs

Jquery ui datepicker在点击输入时不起作用。

main.js

require.config({
    baseUrl: "js",
    paths: {
        html5shiv: "libs/html5shiv",
        jquery: "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
        jqueryui: "http://code.jquery.com/ui/1.10.3/jquery-ui",
        tablesorter: "libs/jquery.tablesorter.min",
        script: "script",
        underscore: "libs/underscore.min",
        backbone: "libs/backbone.min",
        utils: "utils",
        collectorModel: "models/collectorModel",
        collectorCollection: "collections/collectorCollection",
        tollectorRouter: "routers/tollectorRouter",
        edit: "views/collector/tollector_edit",
        index: "views/collector/collector_index",
        neww: "views/collector/collector_new",
        row: "views/collector/collector_row",
        show: "views/collector/collector_show",
        'templates': 'templates'
    },
    shim: {
        jqueryui: {
            deps: ["jquery"],
            exports: "Jqueryui"
        },
        tablesorter: {
            deps: ["jquery"],
            exports: "TableSorter"
        },
        script: {
            deps: ["jquery", "jqueryui", "tablesorter"],
            exports: "Script"
        },
        jqueryui: {
            deps: ["jquery"]
        },
        underscore: {
            exports: "_"
        },
        backbone: {
            deps: ["underscore", "jquery"],
            exports: "Backbone"
        }
    }

});

require(["backbone", "underscore", "collectorCollection", "collectorRouter", "script"],
    function (Backbone, _, CollectorCollection, CollectorRouter) {
        var collectors = new CollectorCollection();
        var router = new CollectorRouter({collectors: collectors});
        Backbone.history.start();
    });

模板:collector_edit.html

input type="text" class="inputs dateInput" name="endDate" placeholder="End date" value="<%= endDate %>

scripts.js中

$(document).ready(function () {
    $(".dateInput").datepicker({dateFormat: "dd/mm/yy"});
});

在使用骨干和RequireJS

之前有效

1 个答案:

答案 0 :(得分:1)

使用requireJS时,您的依赖项不再存在于全局范围内,而只存在于需要它们的modulde中。尝试将脚本JS更改为:

define(['jqueryui'], function( jqueryui ) {
  $(document).ready(function () {
    $(".dateInput").datepicker({dateFormat: "dd/mm/yy"});
  });

})