Using Marionette CollectionView to create multiple views per item

∥☆過路亽.° 提交于 2019-12-11 11:26:05

问题


I have a Marionette.CollectionView that for certain items (models) need to create 2 views to run on the model, can Marionette.CollectionView.buildItemView return 2 views?

EDIT:

I don't want to create some another WrapperItemView, I already have some solution running right now but I want to make it more standart.

I want my code to be look like this, is there a simple way to make it work?

  buildItemView: function(item){
    // create 2 views based on item type 
    return [view1, view2];
  },
  appendHtml: function(collectionView, itemView, index){
    if (itemView.type === "X" ) 
        collectionView.$el.find(".A").append(itemView.el);
    if (itemView.type === "Y" ) 
        collectionView.$el.find(".B").append(itemView.el);
  }

回答1:


why dont your itemview acts as father of the second view, you can create the second view in the initialize function of the item view.

Edit

I would still create a perent view this time I will make it the parent of your 2 views, your the collection will create the parent and the parent will create the two views inside of it.

this way is more natural to me.



来源:https://stackoverflow.com/questions/15891247/using-marionette-collectionview-to-create-multiple-views-per-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!