我怎么能摆脱:类型错误:communityApp.activeTabLayout.pforum未定义 [英] how can I get rid : TypeError: communityApp.activeTabLayout.pforum is undefined

查看:320
本文介绍了我怎么能摆脱:类型错误:communityApp.activeTabLayout.pforum未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模块的我的code为。

spine.module('communityApp',{
    startWithParent:假的,
    定义:功能(communityApp,应用程序,骨干,木偶,$ _){
        的console.log(communityApp.js);

  //设置路由器此模块
    VAR路由器= Marionette.AppRouter.extend({
        之前:函数(){
            的console.log(communityApp.js:router.before())
            App.startSubApp(communityApp,{});
        },
        appRoutes:{
            社区:showCommunityTab
            社区/ pforum:getPforum
            社区/问题:getQuestions
            社区/事件:getEvents
        }
    });    //启动路由器
    App.addInitializer(函数(){
        的console.log(communityApp.js:App.addInitializer())
        //含有活性控制器
        communityApp.activeController =新communityApp.Controllers.tabController();
        //初始化路线
        communityApp.Router =新的路由器({
            控制器:communityApp.activeController
        });
    });    //让程序知道我们开始
    communityApp.addInitializer(函数(){
        的console.log(communityApp.js:DemoApp.addInitializer());
        App.vent.trigger(应用程序:启动,communityApp);
    });    //子应用程序(模块)启动时这将运行
    communityApp.on(开始,函数(){
        的console.log(communityApp.js:在开始());
    });

控制器的 code为。

spine.module(communityApp功能(communityApp,应用程序,骨干,木偶,$ _){
    使用严格的

  //初始化消息选项卡控制器和集合
communityApp.Controllers = {};
communityApp.Collections = {};communityApp.Controllers.tabController = Marionette.Controller.extend({
    showCommunityTab:功能(){
        this.getCommunityTab();
    },
    getCommunityTab:功能(数据){
        // VAR tabLayout =新communityApp.Views.tabLayout();
        //tabLayout.render();
        //创建积极布局
        communityApp.activeTabLayout =新communityApp.Views.tabLayout();
        communityApp.activeTabLayout.render();
        //装载社区模块视图
        App.regionMain.show(communityApp.activeTabLayout);
        //社区模块加载负荷pforum
        this.getPforum();
    },
    getPforum:功能(){
        的console.log('公众论坛标签');
        VAR pforum =新communityApp.Controllers.pforumController();
        pforum.init();    },
    getQuestions:功能(){
        的console.log('问题标签');
        VAR问题=新communityApp.Controllers.questionsController();
        questions.init();    },
    getEvents:功能(){
        的console.log('事件标签');
        VAR的事件=新communityApp.Controllers.eventController();
        events.init();    }
});

code其中的错误是,它是一个标签页。

spine.module(communityApp功能(communityApp,应用程序,骨干,木偶,$ _){
    使用严格的

  communityApp.Controllers.pforumController = Marionette.Controller.extend({
    初始化:功能(){
        VAR FUNC = _.bind(this._getPforum,这一点);
        $。当(App.request('alerts1:实体',{由来:pforum'}))
            。然后(FUNC)
    },
    _getPforum:功能(数据){        //填充数据
        communityApp.activeTabLayout.pforum.show(新communityApp.CollectionViews.pforumCollectionViews({
            采集:数据
        }));
    }
});


解决方案

这是因为你在创建 activeTabLayout getCommunityTab ,和你想创造 getPforum 后访问它。这些都连接到不同的路线。因此,你不说保证为 communityApp.activeTabLayout 存在于您的里面的init 方法。

社区/ pforum - >创建您的控制器,但不是你的标签布局

社区 - >创建您的标签布局,但不是你的控制器

您需要确保 communityApp.activeTabLayout =新communityApp.Views.tabLayout(); 运行之前 pforum.init();

my code of module is.

spine.module('communityApp', { startWithParent: false, define: function (communityApp, App, Backbone, Marionette, $, _) { console.log("communityApp.js");

    // Setup the router for this module
    var Router = Marionette.AppRouter.extend({
        before: function () {
            console.log("communityApp.js: router.before()")
            App.startSubApp("communityApp", {});
        },
        appRoutes: {
            "community": "showCommunityTab",
            "community/pforum": "getPforum",
            "community/questions":"getQuestions",
            "community/events": "getEvents"
        }
    });

    // Startup router
    App.addInitializer(function () {
        console.log("communityApp.js: App.addInitializer()")
        // contains active controller
        communityApp.activeController = new communityApp.Controllers.tabController();
        // initializing route
        communityApp.Router = new Router({
            controller: communityApp.activeController
        });
    });

    // Let app know we started
    communityApp.addInitializer(function () {
        console.log("communityApp.js: DemoApp.addInitializer()");
        App.vent.trigger("app:started", "communityApp");
    });

    // This will run when a sub app (module) starts
    communityApp.on("start", function () {
        console.log("communityApp.js: on 'Start'()");
    });

code of controller is.

spine.module("communityApp", function (communityApp, App, Backbone, Marionette, $, _) { "use strict";

// initializing controllers and collections for message tabs
communityApp.Controllers = {};
communityApp.Collections = {};

communityApp.Controllers.tabController = Marionette.Controller.extend({
    showCommunityTab: function () {
        this.getCommunityTab();
    },
    getCommunityTab: function (data) {
        //var tabLayout = new communityApp.Views.tabLayout();
        //tabLayout.render();
        // creating active layout
        communityApp.activeTabLayout = new communityApp.Views.tabLayout();
        communityApp.activeTabLayout.render();
        // loading community module view
        App.regionMain.show(communityApp.activeTabLayout);
        // load pforum on community module load
        this.getPforum();
    },
    getPforum : function(){
        console.log('Public Forum Tab');
        var pforum = new communityApp.Controllers.pforumController();
        pforum.init();

    },
    getQuestions : function(){
        console.log('Question tab');
        var questions = new communityApp.Controllers.questionsController();
        questions.init();

    },
    getEvents : function(){
        console.log('Events tab');
        var events = new communityApp.Controllers.eventController();
        events.init();

    }
});

Code where error is, Its a tab page.

spine.module("communityApp", function (communityApp, App, Backbone, Marionette, $, _) { "use strict";

communityApp.Controllers.pforumController = Marionette.Controller.extend({
    init: function(){
        var func = _.bind(this._getPforum, this);
        $.when(App.request('alerts1:entities' , {origin:'pforum'}))
            .then(func)
    },
    _getPforum:function(data){

        // populating the data
        communityApp.activeTabLayout.pforum.show(new communityApp.CollectionViews.pforumCollectionViews({
            collection: data
        }));
    }
});

解决方案

That's because you're creating the activeTabLayout in getCommunityTab, and you're trying to access it after creating the controller in getPforum. These are both attached to separate routes. Therefore you're not guarenteed that communityApp.activeTabLayout exists inside of your init method.

community/pforum -> creates your controller, but not your tab layout.

community -> creates your tab layout, but not your controller.

You need to make sure communityApp.activeTabLayout = new communityApp.Views.tabLayout(); runs before pforum.init();

这篇关于我怎么能摆脱:类型错误:communityApp.activeTabLayout.pforum未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆