未捕获的错误:模块加载超时:order!libs/jquery/jquery-min order!libs/underscore/underscore-min order!libs/parse/parse-min libs/jquery/jquery-min libs/underscore/underscore-min libs /parse/parse-min 骨干网 http://requirejs.org/docs/errors.html#timeout
我在 Chrome 的“网络”选项卡下没有 404 请求,也没有脚本错误,所以我不属于该问题的常见错误/修复(根据 requirejs.org)。
当我查看我的网络时,我看到脚本按以下顺序加载:
require.js
main.js
app.js <-- required by main.js
order.js <-- used in main.js to require the next 4 scripts (which aren't AMD)
jquery-min.js <-- required by main.js
underscore-min.js <-- required by main.js
backbone-min.js <-- required by main.js
parse-min.js <-- required by main.js
router.js
login.js
text.js
这对我来说似乎是正确的。下面是我的main.js
,app.js
和代码router.js
。
主.js:
// Author: Thomas Davis <thomasalwyndavis@gmail.com>
// Filename: main.js
// Require.js allows us to configure shortcut alias
// Their usage will become more apparent futher along in the tutorial.
require.config( {
paths : {
jQuery : 'libs/jquery/jquery-min',
Underscore : 'libs/underscore/underscore-min',
Backbone : 'libs/backbone/backbone-min',
Parse : 'libs/parse/parse-min',
templates : '../templates'
}
});
require( [
// Load our app module and pass it to our definition function
'app',
// Some plugins have to be loaded in order due to their non AMD compliance
// Because these scripts are not "modules" they do not pass any values to the
// definition function below
'order!libs/jquery/jquery-min',
'order!libs/underscore/underscore-min',
'order!libs/backbone/backbone-min',
'order!libs/parse/parse-min'
],
function(App) {
// The "app" dependency is passed in as "App"
// Again, the other dependencies passed in are not "AMD" therefore
// don't pass a parameter to this function
App.initialize();
});
应用程序.js:
// Filename: app.js
define( [ 'jQuery', 'Underscore', 'Parse', 'router' ],
function($, _, Parse, Router) {
var initialize = function() {
Parse.$ = $;
// Initialize Parse with your Parse application javascript keys
Parse.initialize("HIDDEN", "ALSO HIDDEN");
// Pass in our Router module and call it's initialize function
Router.initialize();
};
return {
initialize : initialize
};
});
路由器.js:
// Filename: router.js
define( [ 'jQuery', 'Underscore', 'Backbone', 'Parse', 'views/home/login', ],
function($, _, Backbone, Parse, loginView) {
var AppRouter = Backbone.Router.extend( {
routes : {
// Default
'*actions' : 'defaultAction'
},
defaultAction : function(actions) {
// We have no matching route, lets display the home page
loginView.render();
}
});
var initialize = function() {
var app_router = new AppRouter;
Backbone.history.start();
};
return {
initialize : initialize
};
});