插件几乎总是坚持在 jQuery 之前加载。由于我使用了垫片设置,他们不应该这样做。
在我的 main.js 中,我有以下设置:
requirejs.config({
paths: {
'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min',
'bootstrap': '../bootstrap/js/bootstrap.min',
'select2': 'vendor/select2',
'jshashtable': 'vendor/jshashtable-2.1',
'jquery.numberformatter': 'vendor/jquery.numberformatter-1.2.3.min',
'jq-datepicker': 'vendor/bootstrap-datepicker',
'jq-datepicker.da': 'vendor/bootstrap-datepicker.da'
},
// Use shim for plugins that does not support ADM
shim: {
'bootstrap': ['jquery'],
'select2': ['jquery'],
'jq-datepicker': ['jquery'],
'jshashtable': ['jquery'],
'jquery.numberformatter': ['jquery', 'jshashtable']
},
enforceDefine: true
});
在这个文件的后面,我有以下内容:
// Start the main app logic.
requirejs(['jquery', 'bootstrap', 'jq-datepicker'],
function ($) {
console.log('Require.JS loaded');
// Init datepickers
// Docs: https://github.com/eternicode/bootstrap-datepicker
$('.datepicker').datepicker({
format: 'dd/mm/yyyy',
language: 'da',
keyboardNavigation: false,
autoclose: true
});
});
但我一直收到这个错误:
Uncaught TypeError: undefined is not a function bootstrap.min.js:6
(anonymous function) bootstrap.min.js:6
(anonymous function)
我可以在我的 Chrome 网络选项卡中看到它是在 jQuery 之前加载的。
现在我尝试enforceDefine: true
在stackoverflow上环顾四周后添加,但没有运气。我尝试将 requirejs.config 移动到我的 html 页面。我尝试从本地文件加载 jQuery。一切都没有运气。
我错过了什么?