【问题标题】:Can I create 2 itemViewContainers for Marionette's compositeView?我可以为 Marionette 的复合视图创建 2 个 itemViewContainers 吗?
【发布时间】:2013-04-16 05:04:40
【问题描述】:

我正在实现一个 2 列布局视图,如下所示:

但是,当我定义我的木偶复合视图时,似乎只允许使用一个 itemViewContainer。

我可以这样做吗?

class List.Muse extends Marionette.ItemView
  template: JST["backbone/templates/muses/index"]

class List.Muses extends Marionette.CompositeView
  template: JST["backbone/templates/muses/list"]
  itemView: List.Muse
  itemViewContainer: ".left_col"
  itemViewContainer: ".right_col"

//list template
.muses_container.two_col_wrapper.hide
  .left_col
  .right_col
  .clearfix
.loading_container

基本上我想在我的列表模板的“左”和“右”列中交替插入缪斯。可以在复合视图中定义吗?

【问题讨论】:

    标签: listview marionette two-column-layout


    【解决方案1】:

    您要在此处使用的Marionette 视图结构是Layout。您可以将Layout 视为ItemView,它具有用于将子视图渲染到的内置区域。像这样的东西就是你所追求的(在 JS 中。抱歉,我不太了解 CS):

    List.Muses = Marionette.Layout.extend({
      template: JST["backbone/templates/muses/list"],
      regions : {
        leftColRegion : ".left_col",
        rightColRegion : ".right_col"
      },
    
      onRender : function () {
        this.leftColRegion.show(new List.Muse({model : someMuseModel}));
        this.rightColRegion.show(new List.Muse({model : someOtherMuseModel}));
      }
    });
    

    【讨论】:

      【解决方案2】:

      为此,您应该使用 Layout 而不是 CompositeView。布局允许您定义任意数量的区域,然后在每个区域中独立显示一个 ItemView(或任何其他类型的 View)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-09
        • 1970-01-01
        • 2012-08-28
        • 2023-03-31
        • 2015-08-27
        • 2021-03-14
        • 2020-01-12
        • 1970-01-01
        相关资源
        最近更新 更多