本文介绍了引导,日期选择器没有得到匀与requirejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建设有Backbone.js的+ require.js一个应用程序。我想在我的应用程序使用的日期选择在这里:

I am building a application with backbone.js + require.js. I want to use datepicker from here in my application: datepicker

由于其非AMD,我垫片它requirejs是这样的:

Since its non-AMD, i shim it in requirejs like this:

require.config({
baseUrl: "appjs",

paths:{
    jquery: '../layout_assets/assets/js/libs/jquery-1.8.2.min',
    dt: '../layout_assets/plugins/datatables/jquery.dataTables.min',
    dtPlugins:'../layout_assets/plugins/datatables/dtplugins',
    dtBootstrap: '../layout_assets/plugins/datatables/dataTables.bootstrap',
    underscore: '../assets/js/underscore-min',
    Backbone: '../assets/js/backbone-min',
    bootstrap: '../assets/js/bootstrap.min',
    datepicker:'../layout_assets/bootstrap-datepicker'
    },

    shim: {
        underscore:{
            exports:"_"
        },

        Backbone:{
            deps: ['underscore','jquery'],
            exports: "Backbone"
        },

        dt: {
        deps:['jquery'],
        exports: "dt"   
        },

        dtPlugins: {
            deps:['jquery','dt'],
            exports:"dtPlugins"
            },
        bootstrap: {
        deps:['jquery'],
        exports:"bootstrap"

        },
        dtBootstrap: {
            deps: ['dt','jquery'],
            exports: "dtBootstrap"
        },

        datepicker:{
        deps:['jquery','bootstrap'],
        exports:"datepicker"
        }

        }

});

现在在我的看法我叫日期选择像这样的:

Now in one of my views i call datepicker like this:

define(['Backbone',
        'underscore',
        'jquery',
        'datepicker',
        'models/reports',
        'dtBootstrap',
        'bootstrap',
        'text!templates/reports/dashboard.html',
        ],function(Backbone,_,$,dp,report,dtBootstrap,bootstrap,dashboard){


        var view=Backbone.View.extend({
            el:"#content-wrap",
            template:_.template(dashboard),
            render:function(){
            this.$("#container-left").html(this.template());
            console.log(dp);
            }

    });
    return view;
    });

这将返回在控制台上不确定的。我猜库没有得到妥善匀。

This returns undefined on the console. I guess the library is not getting shimmed properly.

推荐答案

这是我使用的垫片:

"datepicker" : {
    deps: ["jquery-ui", "bootstrap"],
    exports: "$.fn.datepicker"
}

"datepicker": "lib/datepicker/js/bootstrap-datepicker"

这篇关于引导,日期选择器没有得到匀与requirejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:54