I plug-in richiedono quasi sempre il caricamento prima di jQuery. E non dovrebbero farlo a causa del mio uso dello shim setting.RequireJS non funziona con i plugin jQuery Shim'ed
Nei miei main.js ho queste impostazioni:
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
});
avanti in questo file ho il seguente:
// 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
});
});
Ma io ottenere questo errore per tutto il tempo:
Uncaught TypeError: undefined is not a function bootstrap.min.js:6
(anonymous function) bootstrap.min.js:6
(anonymous function)
E posso vedere nella mia scheda Rete di Chrome che viene caricato prima di jQuery.
Ora ho provato ad aggiungere il enforceDefine: true
dopo aver guardato qui intorno su StackOverflow, ma senza fortuna. Ho provato a spostare il requirejs.config nella mia pagina html. E ho provato a caricare jQuery da un file locale. Tutto senza fortuna.
Cosa mi manca?
ho testato il tuo esempio e non vedere eventuali problemi: http://jsfiddle.net/asgoth/tHkHw/Ho rimosso enforceDefine e jq-datepicker.da (impossibile trovarlo) – asgoth