سؤال

I am implementing a 2 column layout view as shown below:

enter image description here

However it seems that when I define my marionette composite view, only a single itemViewContainer is allowed.

Can I do something like this?

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

Essentially I would like to alternate insertion of muses into the 'left' and 'right' column in my list template. Is that possible to define in the composite view?

هل كانت مفيدة؟

المحلول

The Marionette view construct that you want to use here is a Layout. You can think of a Layout as an ItemView that has regions built in for rendering sub views into. Something like this is what you are after (in JS. Sorry I don't really know 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}));
  }
});

نصائح أخرى

For this you should be using a Layout instead of CompositeView. Layout lets you define as many regions as you would like and then display an ItemView (or any other type of View) independently into each of those regions.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top