javascript – require.js模块未正确加载

前端之家收集整理的这篇文章主要介绍了javascript – require.js模块未正确加载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有我的bootstrap文件定义了require.js路径,并加载了app和config模块.
  1. // Filename: bootstrap
  2.  
  3. // Require.js allows us to configure shortcut alias
  4. // There usage will become more apparent futher along in the tutorial.
  5. require.config({
  6. paths: {
  7. 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'
  8. }
  9. });
  10. console.log('loading bootstrap');
  11. require([
  12. // Load our app module and pass it to our definition function
  13. 'app','config'
  14. ],function(App){
  15. // The "app" dependency is passed in as "App"
  16. // Again,the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
  17. console.log('initializing app');
  18. App.initialize();
  19. });

app.js是像它应该加载的,它的依赖关系被加载.调用它的定义回调,所有正确的依赖关系作为参数传递.没有错误被抛出.然而,在bootstrap的回调中,App是未定义的!没有参数被通过.可能是什么原因造成的?这是我的应用程序文件(修改为空格)

  1. // Filename: app.js
  2. define(
  3. 'app',[
  4. 'jquery','underscore','backbone','jquery-ui','bfwd/core','plugins/jquery.VistaProgressBar-0.6'
  5. ],function($,_,Backbone){
  6. var initialize = function()
  7. {
  8. //initialize code here
  9. }
  10. return
  11. {
  12. initialize: initialize
  13. };
  14. }
  15. );

解决方法

据我所知,你应该可以在app.js define方法中放置“app”字符串.
  1. // Filename: app.js
  2. define([
  3. 'jquery','plugins/jquery.VistaProgressBar-0.6'
  4. ],Backbone){
  5. ...
  6. );

猜你在找的JavaScript相关文章