要求模块未定义

时间:2013-12-13 12:02:24

标签: backbone.js requirejs

我有一个模块&C 39,我已经在模块A'中要求了。我可以访问模块' C'在模块' A'。 我的新模块' B'还需要那个模块。实施' B'与A'中的相同,但我的新模块会返回一个未定义的模块。

模块B(js / controller / delete.js):

define([
    'jquery',
    'underscore',
    'backbone',
    'views/Box/BrowserView'
], function($, _, Backbone, browser){

alert(browser.created);            //alert -> can't read created of undefined

[...]

});

模块A(js / mainView.js):

define([
'jquery',
'underscore',
'backbone',
'views/Box/BrowserView',
'jqm',
'socketio'
], function($,_, Backbone, browser){

    alert(browser.created)      //alerts false (browser is required)

});

模块C(js / views / Box / BrowserView.js)

define([
'jquery',
'underscore',
'backbone',
'text!templates/template.html',
'Controller/delete',
'jqm'
], function($,_,Backbone, bvtemp, delete){

var created = false;
[...}

return{
    [...],
    created : created
}

编辑:需要配置

var require = {
paths: {
    overrides   :'overrides',
    jquery      :'libs/jquery/jquery-1.9.1.min',
    underscore  :'libs/underscore/underscore-min',
    backbone    :'libs/backbone/backbone-min',
    //
    jqm         :'libs/jquery-mobile/jquery.mobile-1.3.0.min',
    socketio    :'libs/socketio/socket.io',
    webSocket   :'websocket/socketConnection',
    text        :'text',
    templates   :'templates'
},
shim: {
    'overrides'  : {deps: ['jquery']},
    'backbone'   : {deps: ['underscore', 'jquery'],exports: 'Backbone' },
    'jqm'        : {deps: ['jquery'],              exports: 'jqm'},
    'underscore' : {                               exports: '_'},
    'websocket'  : {deps:['socketio']},
    'templates'  : {deps: ['jqm']}
}};

enter image description here

0 个答案:

没有答案