Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 木偶嵌套复合视图_Backbone.js_Marionette - Fatal编程技术网

Backbone.js 木偶嵌套复合视图

Backbone.js 木偶嵌套复合视图,backbone.js,marionette,Backbone.js,Marionette,我可以使用嵌套复合视图生成这样的输出吗 Nike Football, Basketball Reebok Football, Basketball, Running 我确实用这种方式编写了嵌套复合视图。我不确定是否有其他更好的方法或最佳实践方法来实现这一点 结构: BrandCompositeView itemView: Layout1 #brand<-BrandView (Nike, Reebok) #spo

我可以使用嵌套复合视图生成这样的输出吗

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
是的,这是可能的


我在树结构中使用的方法-

如果我想创建这个(包含多个子项的集合)如何

汽车:[
{
Car1
姓名:car1
图像:[{img1},{img2},{img3}]
评论:[{comment1},{comment2},{comment3}]
价格:$1000
},
{
Car2
姓名:car1
图像:[{img1},{img2},{img3}]
评论:[{comment1},{comment2},{comment3}]
价格:$2000
}
]

  • 事实上,我几天前刚刚写了一个答案,可能会对你有所帮助。看看这条线-


    基本上,它让您使用主干关系自动处理所有嵌套。然后,您可以在复合视图的内部将其抽象为复合视图。

    因此,您有一个品牌集合,每个品牌都有一个体育活动集合,您必须将其呈现为嵌套列表?是的,这只是一个示例。我必须做类似的事情。它现在正在工作,但我不确定这是正确的方式来做这件事
    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);
    }
    
    Car: [
        {
        Car1
           name: car1
           image: [{img1}, {img2}, {img3}]
           comment: [{comment1}, {comment2}, {comment3}]
           price: $1000
        },
        {
        Car2
           name: car1
           image: [{img1}, {img2}, {img3}]
           comment: [{comment1}, {comment2}, {comment3}]
           price: $2000
        }
    ]
    
    
    <script id="car-template" type="text/template">
      <li><%= name %></li>
      <div id="photo-container"></div>
      <li><%= price %></li>
      <div id="comment-container"></div>
    </script>