Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js&;Require.js-应用程序组件可以';不能与路由器通信_Backbone.js_Namespaces_Requirejs - Fatal编程技术网

Backbone.js&;Require.js-应用程序组件可以';不能与路由器通信

Backbone.js&;Require.js-应用程序组件可以';不能与路由器通信,backbone.js,namespaces,requirejs,Backbone.js,Namespaces,Requirejs,我正在一个新的Require/Backbone应用程序上进行初始设置,我似乎无法让我的“全局资源”对象与一些子模块通信。我怀疑这与循环依赖有关,但我不确定在哪里/为什么/如何 在configure.js中加载所有填隙项目后,应用程序将启动: /* kick off */ define([ 'cxn/newUI/rr', 'cxn/newUI/routers/mainRouter' ], function( app, MainRouter) { // create ro

我正在一个新的Require/Backbone应用程序上进行初始设置,我似乎无法让我的“全局资源”对象与一些子模块通信。我怀疑这与循环依赖有关,但我不确定在哪里/为什么/如何

configure.js中加载所有填隙项目后,应用程序将启动:

/* kick off */
define([ 
    'cxn/newUI/rr',
    'cxn/newUI/routers/mainRouter'
], function( app, MainRouter) {

    // create router
    app.router = new MainRouter({
        model: app
    });

    Backbone.history.start({
        pushState: true,
        root: app.rootURL
    });
});
rr.js是我的“资源注册表”,其中定义了所有全局应用程序内容

define(['underscore', 'backbone'], function(_, Backbone) {

    // main namespace object
    var ResourceRegistry = {

        rootURL: '/',
        models: {},
        views: {},
        collections: {},
        router: {},
        eventBus: _.extend( {}, Backbone.Events ),
        tplCache: {}

    };

    return ResourceRegistry;
});
MymainRouter.js启动,完成路由准备,并加载主控制器:

define([
'cxn/newUI/rr',
'cxn/newUI/controllers/_mainAppController',
'cxn/newUI/controllers/homeController',
'cxn/newUI/controllers/inboxController'
], function( app, MainAppController, HomeController, InboxController ) {

function cleanup() {
    if (currentPage && currentPage.destroy) {
        currentPage.destroy();
    }
}

var currentPage;

var MainRouter = Backbone.Router.extend({

    routes: {
        ''                  : 'index',
        'home'              : 'home',
        'messages'          : 'showInbox',
        'messages/:id'      : 'showMessage',
        'patient/:id'       : 'showPatient'
    },

    initialize: function(options) {
        this.model = options.model;
        this.eventBus = app.eventBus;
        this._listenForEvents();
    },

    // route definition methods
    index: function() {
        MainAppController.initialize({ eventBus: app.eventBus });
        return this;
    },

    ....
最后,我的主控制器加载并执行一个“postininitialize”钩子,在这个钩子中,一切都会突然停止

define([
'cxn/newUI/rr',

'cxn/newUI/controllers/_baseController',

'cxn/newUI/views/_mainAppView/pageHeaderView',
'cxn/newUI/views/_mainAppView/mainContentView',
'cxn/newUI/views/_mainAppView/pageFooterView',
'cxn/newUI/views/_mainAppView/pageBottomDrawerView'

], function( app, Controller, PageHeaderView, MainContentView, PageFooterView, PageBottomDrawerView ) {

// Define the "new" collections/models/etc to pass to the controller here

// Define the controller
var MainAppController = new Controller({

    name: '_mainAppController',

    app: app,

    postInitialize: function() {

        app.eventBus.on('mainContentArea:loaded', function(route) {
            if (!route) {
                return app.router.navigate('home');
            }
            else {
                return app.router.navigate(route);
            }
        });

        //this._setupDocumentReady();
    },
我得到错误
uncaughttypeerror:Object#没有方法“导航”


通过在Chrome开发工具中设置断点,我可以看到“app.router”,尽管在初始启动中已定义,但它不是我的全局命名空间的一部分,因此控制器无法使用它。我错过什么了吗?我没有正确定义它吗?

您没有包括mainRouter.js的最后一部分。。。 一个愚蠢的问题:你加了吗

return MainRouter;

最后?

我确实返回了主路由器,是的。