用木偶的CollectionView创建每个项目的多个视图 [英] Using Marionette CollectionView to create multiple views per item
问题描述
我有一个Marionette.CollectionView,对于某些项目(型号)需要创建2次,以在模型上运行,也可以Marionette.CollectionView.buildItemView返回2次?
修改
我不希望创造一些其他WrapperItemView,我已经有了一些解决方案,现在运行,但我想让它更非标准。
我希望我的code是这个样子,有一个简单的方法,使工作?
buildItemView:函数(项目){
//根据项目类型创建2次
返回[视图1,视图2]。
},
appendHtml:功能(的CollectionView,ItemView控件,指数){
如果(itemView.type ===X)
。$的CollectionView el.find(A)追加(itemView.el)。
如果(itemView.type ===Y)
的CollectionView $ el.find追加(itemView.el)。(B)。;
}
为什么不ItemView控件您作为第二种观点的父亲,您可以创建在项目视图的初始化函数的第二个观点。
修改
我仍然会创建一个perent鉴于这次我将使它的你2次父,你的收集将创建父和母将创建它里面的两种观点。
这种方式更自然给我。
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);
}
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.
这篇关于用木偶的CollectionView创建每个项目的多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!