0

现在我有一个返回的集合数据,例如:

[{'category':1,
     'title':"Current Company", 
     'people':{"count":2,                
             "keyword":"",
             "executiveInfos":[{"name":"Darren Suomi", 
                                "title":"Global Vice President of Sales",
                                "companyId":2867257,
                                "employmentId":10993552,
                                "executiveId":10152454,
                             "imageUrl":"https://d1tzls7byl3ryp.cloudfront.net/iv/profileImages/executiveImage/321446",
                                "count":0,
                                "executiveConnectionImageUrls":[],
                                "trackedByWatchlists":[],
                                "employmentType":0},
                               {"name":"Gregory  Gunn",
                                "title":"Vice President of Business Development",
                                "companyId":2867257,
                                "employmentId":9240823,
                                "executiveId":9049103,
                                "imageUrl":"https://d1tzls7byl3ryp.cloudfront.net/iv/profileImages/executiveImage/292479",
                                "count":0,
                                "executiveConnectionImageUrls":[],
                                "trackedByWatchlists":[],
                                "employmentType":0}]***}
     },
{'category': 2, 
 'title':"Former Company",
 'people':{"count":0,
         "finance":0,
         "otherFunction":0,
         "keyword":"",
         "executiveInfos":[]}
},
{'category': 4,
 'title':"Family Tree Company",
 'people':{"count":0,
         "keyword":"",
         "executiveInfos":[]}
 }
]

在数据中,它有3个类别,在每个类别中都有一个名为people的属性,现在我想列出每个类别中人的executiveInfos,我的listview是:

var PeopleListView =  Backbone.View.extend({
    el: $('.bucketContent'),
    initialize:  function(){
        this.listenTo(this.collection, 'reset', this.render);
    }
        render: function() {
           this.collection.each( function( $model) {                
            var itemview = new PeopleItemView({model : $model});                    
            this.$el.prepend(itemview.render().el);  

        }, this);

        return this;
    }
});

我应该怎么办?谢谢你。

4

1 回答 1

0

不知道是什么PeopleItemView,很难给你一个正确的答案。但是,假设您正确地实现了这个视图,您需要确保您正确地将所有模型属性传递给您的模板。

例如,假设PeopleItemView视图看起来像这样:

var PeopleItemView = Backbone.View.extend({
  this.template = JST["the_template_name"];
  render: function() {
    this.$el.html(this.template(this.model.attributes));
    return this;
  }
});

然后,您可以遍历executiveInfos模板本身。在 Handlebars 中,这看起来像:

{{#each people.executiveInfos}}
    <span>{{name}}</span>
    <span>{{title}}</span>
    <span>{{companyId}}</span>
    <span>{{employmentId}}</span>
    <span>{{executiveId}}</span>
    ...
{{/each}}
于 2013-10-22T15:45:37.917 回答