我在定义数组中加载最后一个模块时遇到错误。
例如:
define(['jquery', 'js/custom','moment','bootstrap','datetimepicker'], function ($, custom) {
$('#input_start_date').datetimepicker({});
));
Getting an error:
Uncaught TypeError: $(...).datetimepicker is not a function
define(['jquery', 'js/custom', 'chart'], function ($, custom) {
var barChart = new Chart(BARCHART_RegistrantComparison, {});
});
Getting an error:
Uncaught TypeError: Chart is not a function
define(['jquery', 'js/custom', 'bootstrap', 'mCustomScrollbar'], function ($, c) {
$("nav.side-navbar").mCustomScrollbar({
scrollInertia: 200
});
});
Getting an error:
Uncaught TypeError: $(...)mCustomScrollbar is not a function
我尝试通过需求链设置定义,但没有解决问题。
例如:
define(['jquery'], function($) {
require(['js/custom'], function(c) {
require(['bootstrap'], function () {
require(['mCustomScrollbar'], function () {});
});
});
});
以下是我的require.js配置。
var require = {
baseUrl: '/jsp/assets',
deps:['jquery','js/main'],
waitSeconds: 50,
enforceDefine : false,
paths: {
"jquery": ['vendor/jquery/jquery.min'],
"jqueryUI": ['js/jquery-ui.min'],
"bootstrap": ['vendor/bootstrap/js/bootstrap.bundle.min'],
"moment": ['vendor/moment/min/moment.min'],
"datetimepicker": ['js/external/bootstrap-datetimepicker.min'],
"chart" : ['vendor/chart.js/Chart.min'],
"mCustomScrollbar" : ['vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min']
},
shim: {
"jquery": {exports: ['$', 'jQuery']},
"jqueryUI": {
exports: '$',
"deps": ['jquery']
},
"bootstrap": {
"deps": ['jquery']
},
"mCustomScrollbar": {
exports: 'mCustomScrollbar',
"deps": ['jquery']
},
"chart" : {
"deps": ['jquery']
},
"datetimepicker": {
"deps": ['moment','bootstrap']
}
},
urlArgs: "1.0"
};
任何人都面临类似的问题或有任何建议,我们将不胜感激。
谢谢