在清除我的緩存後的應用程序的初始負載我得到一個jquery未定義bc應用程序正試圖加載jquery驗證之前jquery已加載。刷新後,所有內容都可以加載並正常工作。我以爲我正確設置了這一點,但我錯過了什麼?使用backbone.js,require.js和jquery。腳本加載順序錯誤 - require.js
Main.js:
require.config({
paths: {
'jquery': 'libs/jquery/jquery-min',
'underscore': 'libs/underscore/underscore-min',
'backbone': 'libs/backbone/backbone-min',
'validate': 'jquery.validate-1.11.1.min',
'templates': '../templates'
},
shim: {
jquery: {
exports: "jquery"
},
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore', 'jquery'],
exports: "backbone"
},
validate: {
deps: ['jquery'],
exports: "validate"
}
},
});
require([
'app'
], function(App){
App.initialize();
});
App.js
define([
'jquery',
'underscore',
'backbone',
'validate',
'router',
'scripts'
], function($, _, Backbone, validate, Router, scripts){
var initialize = function(){
Router.initialize();
};
return {
initialize: initialize
};
});
這裏是我的文件更新,但仍然沒有運氣:
require.config({
paths: {
'jquery': 'libs/jquery/jquery-min',
'underscore': 'libs/underscore/underscore-min',
'backbone': 'libs/backbone/backbone-min',
'validate': 'jquery.validate-1.11.1.min',
'templates': '../templates'
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore', 'jquery'],
exports: "Backbone"
},
validate: {
deps: ['jquery', 'backbone'],
exports: "validate"
}
}
});
require([
'app'
], function(App){
App.initialize();
});
應用.js
define([
'jquery',
'underscore',
'backbone',
'validate',
'router',
'scripts'
], function($, _, Backbone, validate, Router, scripts){
var initialize = function(){
Router.initialize();
};
return {
initialize: initialize
};
});
我檢查了firebug html,它看起來像腳本正確的順序加載 - 要求,主要,應用程序,jquery,下劃線,骨幹,驗證,但我仍然得到的jquery是未定義錯誤的驗證插件。 – user1572796