Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/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

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
Design patterns 主干子视图和交换机_Design Patterns_Backbone.js_Views_Subviews - Fatal编程技术网

Design patterns 主干子视图和交换机

Design patterns 主干子视图和交换机,design-patterns,backbone.js,views,subviews,Design Patterns,Backbone.js,Views,Subviews,出乎意料,它看起来怎么样?ActiveWindow类似于主容器,位于子视图下方。路由器触发activewindow.render(选项),然后交换机运行。 这样做可以吗?或者有多糟糕 define('activewindowView', [ 'backbone', 'text!views/activewindowView/activewindowTemplate.html', 'ghostviewHunter', 'menuView', 'commerce

出乎意料,它看起来怎么样?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;

})

这应该行得通。另一个选项是,如果可以,将对视图构造函数的引用作为
options.subview
,然后执行
this.subview=newoptions.subview(options)
。或者,如果你不能做到这一点,你可以有一个对象,阻碍了正确的看法<代码>视图={menu:MenuView,…,commerces:CommercesView},然后
this.subview=新视图[options.subview](选项)。无论如何,给猫剥皮的方法不止一种。我觉得这个问题很有用,也很清楚,但它非常适合猫。