@H_301_1@我有我的bootstrap文件定义了require.js路径,并加载了app和config模块.
// 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 define方法中放置“app”字符串.
// Filename: app.js define([ 'jquery','plugins/jquery.VistaProgressBar-0.6' ],Backbone){ ... );