【发布时间】:2014-09-02 06:22:02
【问题描述】:
我可以使用嵌套复合视图来制作这样的输出吗?
Nike
Football, Basketball
Reebok
Football, Basketball, Running
我确实以这种方式编写了嵌套复合视图。我不确定是否有其他更好的方法或最佳实践方法来实现这一点。
结构:
BrandCompositeView
itemView: Layout1
#brand<-BrandView (Nike, Reebok)
#sport<-SportCompositView
itemView: SportView
BrandCompositeView (generate Nike, Reebok),
itemView of BrandCompositeView is a layout1 with div id are(#brand, #sport)
SportCompositView (generate Football, Basketball, Running)
itemView of SportCompositView is SportView
BrandView and SportView are itemView
Layout1 is Marionette.Layout
在 Layout1.js 中
initialize:function(){
this.brandView = new BrandView({"model": this.model});
this.sportView = new SportCompositView({"collection":collection});
}
onRender: function () {
this.brand.show(this.brandView);
this.sport.show(this.sportView);
}
【问题讨论】:
-
所以你有一个品牌的集合,每个品牌都有体育活动的集合,你必须把它渲染成一个嵌套列表?
-
是的,这只是一个例子。我必须做类似的事情。它现在正在工作,但我不确定它是否是正确的方法。
-
查看这篇文章 - 它非常接近您正在寻找的内容stackoverflow.com/questions/25232982/…