2013-10-22 121 views
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個類別,每個類別有一個人屬性命名,現在我 要列出我的列表視圖是:

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; 
    } 
}); 

我該怎麼辦?謝謝。

+0

你有什麼試過?你需要迭代集合中的模型,然後對每個模型迭代'model.people.executiveInfos'。 –

回答

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通過模板本身迭代。在把手看起來像這樣:

{{#each people.executiveInfos}} 
    <span>{{name}}</span> 
    <span>{{title}}</span> 
    <span>{{companyId}}</span> 
    <span>{{employmentId}}</span> 
    <span>{{executiveId}}</span> 
    ... 
{{/each}} 
+0

我可以更改使用解析函數僅返回每個類別中的executiveInfos的返回集合嗎? – user2528222

+0

絕對!如果你只關心executiveInfos領域,那麼你絕對可以這樣做。 –