提问者:小点点

如何使用主干控制器和视图进行嵌套选项卡(子选项卡)?


我是主干网开发的初学者,我正在尝试使用主干网开发生命周期管理。该项目包含四个主选项卡,每个选项卡中都有子选项卡。我使用控制器、模型和视图等创建了主选项卡。我还添加了导航滑块

这一切都很好,但我对如何在主选项卡中加载子选项卡感到困惑。我的主要问题是,在哪里启动子选项卡的控制器?是否来自主选项卡控制器的初始化方法?

代码概述:-主控制器加载每个选项卡的集合和模型-单击主选项卡时,主控制器显示每个选项卡的视图

// Declare pages collection
var mainpages = new TST.Collections.Pages([ new SCL.Models.Page({
    id : 1,
    name : "Main Tab1",
    route : "!/tab1",
    _controller : TST.Controllers.Tab1
}), new SCL.Models.Page({
    id : 2,
    name : "Main Tab2",
    route : "!/tab2",
    _controller : TST.Controllers.Tab2
}) ], {
    current : 1
});

// show the main layout
var layout = new TST.Layouts.Main({
    collection : mainpages
});
this.options.region.show(layout);

// show the menu
var menu = new TST.Views.Nav({
    collection : mainpages
});
layout.menu.show(menu);

区域在主布局中声明。并显示每个选项卡在选项卡点击使用-

每个标签的控制器看起来像这样

SCL.Routers.Tab1= Backbone.Marionette.AppRouter.extend({
    appRoutes : {
        "!/request" : "start"
    }
});

  SCL.Controllers.Tab1= TST.Framework.Controller.extend({
    initialize : function(options) {
        this.layout = new TST.Layouts.Tab1();
        this.router = new TST.Routers.Tab1({
            controller : this
        });
    },

    start : function() {
        app.vent.trigger("page:change", {
            view : this.layout
        });
    }
});

那么现在,我如何在Tab1下加载子选项卡??

请分享你的想法,帮助我...提前感谢!


共1个答案

匿名用户

根据德里克·贝利的原始文章(http://lostechies.com/derickbailey/2012/04/05/composite-views-tree-structures-tables-and-more/),我写了一篇关于类似问题的博客文章:http://davidsulc.com/blog/2013/02/03/tutorial-nested-views-using-backbone-marionettes-compositeview/

你应该能够应用博客文章中的内容来解决你自己的挑战,因为它的性质非常相似。