我可以使用嵌套复合视图来制作像这样的输出吗?Marionette嵌套复合视图
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);
}
所以你有一个品牌的集合,每个品牌都有体育活动的集合,你必须渲染它像一个嵌套列表? – Evgeniy 2014-09-02 06:24:37
是的,这只是一个例子。我必须做类似的事情。它现在正在工作,但我不知道这是否正确的方式来做到这一点。 – Fingercross 2014-09-02 06:33:33
结帐这篇文章 - 它非常接近你要找的东西http://stackoverflow.com/questions/25232982/backbone-fetch-related-models/25236715#25236715 – Evgeniy 2014-09-02 06:44:30