我有我的 Bootstrap 文件,它定义了 require.js 路径,并加载了应用程序和配置模块。
// Filename: bootstrap
// Require.js allows us to configure shortcut alias
// There usage will become more apparent futher along in the tutorial.
require.config({
paths: {
bfwd: 'com/bfwd',
plugins: 'jquery/plugins',
ui: 'jquery/ui',
jquery: 'jquery/jquery.min',
'jquery-ui': 'jquery/jquery-ui.min',
backbone: 'core/backbone.min',
underscore: 'core/underscore.min'
}
});
console.log('loading bootstrap');
require([
// Load our app module and pass it to our definition function
'app',
'config'
], 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
console.log('initializing app');
App.initialize();
});
app.js 已按应有的方式加载,并且它的依赖项已加载。它的定义回调被调用,所有正确的依赖项作为参数传递。不会抛出任何错误。但是,在 Bootstrap 的回调中,App 是未定义的!没有参数被传递。是什么原因造成的?这是我的应用程序文件(修改了空间)
// Filename: app.js
define(
'app',
[
'jquery',
'underscore',
'backbone',
'jquery-ui',
'bfwd/core',
'plugins/jquery.VistaProgressBar-0.6'
],
function($, _, Backbone){
var initialize = function()
{
//initialize code here
}
return
{
initialize: initialize
};
}
);
最佳答案
据我所知,您应该只在 app.js 定义方法中删除“app”字符串。
// Filename: app.js
define([
'jquery',
'underscore',
'backbone',
'jquery-ui',
'bfwd/core',
'plugins/jquery.VistaProgressBar-0.6'
], function($, _, Backbone){
...
);
关于javascript - require.js 模块未正确加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9788288/