主干子视图并切换

时间:2016-04-08 14:53:33

标签: design-patterns backbone.js views subviews

出乎意料的是,它看起来如何? ActiveWindow就像主容器一样,位于子视图下方。路由器触发activewindow.render(选项)然后交换机运行。 这样做好吗?或者有多糟糕?

define('activewindowView', [
    'backbone',
    'text!views/activewindowView/activewindowTemplate.html',
    'ghostviewHunter',
    'menuView',
    'commercesView',
    'horairesView',
    'servicesView',
    'destinationsView',
    'breadcrumbView',
    'staytunedView',
    'helpView',
    'transportsView',
    'aroundView',
    'infoslegalesView',
    'royalsliderView',
    'anomalieView',
    'anomalieReportView',
    'searchView'
    ], function(Backbone, ActivewindowTemplate, GhostviewHunter, MenuView, CommercesView, HorairesView, ServicesView, DestinationsView, BreadcrumbView, StaytunedView, HelpView,
     TransportsView, AroundView, InfoslegalesView, RoyalsliderView, AnomalieView, AnomalieReportView, Searchview) {

    var ActivewindowView = Backbone.View.extend({
        el: '#activewindow',

        template: _.template(ActivewindowTemplate),

        events: {},

        initialize: function() {
            _.bindAll(this, 'render', 'renderSubview');
        },

        render: function(options) {
            this.$el.html(this.template(options));
            this.renderSubview(options);
        },

        renderSubview: function(options) {
            // create fil d'ariane view
            this.breadcrumbView = new BreadcrumbView();
            GhostviewHunter.addView(this.breadcrumbView);
            // render activewindow subview
            switch(options.subview) {
                case 'menu':
                    this.menuView = new MenuView();
                    this.menuView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.menuView);
                    break;
                case 'commerces':
                    this.commercesView = new CommercesView(options);
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.commercesView);
                    break;
                case 'horaires':
                    this.horairesView = new HorairesView();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.horairesView);
                    break;
                case 'services':
                    this.servicesView = new ServicesView(options);
                    //this.servicesView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.servicesView);
                    break;
                case 'destinations':
                    this.destinationsView = new DestinationsView(options);
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.destinationsView);
                    break;
                case 'staytuned':
                    this.staytunedView = new StaytunedView(options);
                    this.staytunedView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.staytunedView);
                    break;
                case 'help':
                    this.helpView = new HelpView();
                    this.helpView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.helpView);
                    break;
                case 'transports':
                    this.transportsView = new TransportsView(options);
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.transportsView);
                    break;
                case 'around':
                    this.aroundView = new AroundView(options);
                    this.aroundView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.aroundView);
                    break;
                case 'infoslegales':
                    this.infoslegalesView = new InfoslegalesView();
                    this.infoslegalesView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.infoslegalesView);
                    break;
                case 'royalslider':
                    this.royalsliderView = new RoyalsliderView(options);
                    GhostviewHunter.addView(this.royalsliderView);
                    break;
                case 'anomalie':
                    this.anomalieView = new AnomalieView(options);
                    this.anomalieView.render();
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.anomalieView);
                    break;
                case 'anomalieReport':
                    this.anomalieReportView = new AnomalieReportView(options);
                    this.anomalieReportView.render(options);
                    this.breadcrumbView.render(options);
                    GhostviewHunter.addView(this.anomalieReportView);
                    break;
                /*case 'search':
                    this.*/
            }
        }

    });

    return ActivewindowView;

})

0 个答案:

没有答案