在清除我的缓存后的应用程序的初始加载中,我得到一个 jquery is undefined bc 应用程序试图在 jquery 加载之前加载 jquery validate。刷新后,一切都加载并正常工作。我以为我设置正确,但我错过了什么吗?使用backbone.js、require.js 和jquery。
主.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();
});
应用程序.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
};
});