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

标签 javascript requirejs

我有我的 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/

相关文章:

javascript - 结合宽度媒体查询和 JQuery Scroll top

javascript - 在 Durandal 构建中从优化中排除文件

node.js - 为什么我不能在nodejs模块中创建闭包

php - 如何统计下载的文件

javascript - 浏览器能否将有效负载数据拆分为多个 websocket 帧?

javascript - 使用 oninput 将 val 发送到输入的问题

javascript - 定义在模块中发生事件时调用的方法

jquery - 将 document.ready 与 require js 一起使用的更简单方法

javascript - 如何在 requirejs 的测试中注入(inject)模块来对应用程序进行单元测试?

javascript - 从其包含的 View 模型访问组件 View 模型