2016-11-11 51 views
3

這裏是我想要做的事:使用嵌套NG重複使用對象數組角

<tr ng-repeat = "data in tabularData track by $index" > 
      <td ng-repeat ="(key,value) in usedAttributes" >{{data[key]}}</td> 

     </tr> 

但這並工作時,表格數據進行結構是這樣的:

[3920F0-3434D3-ADF-3SDF:[{CreatedBy: "John Doe", CreatedDate: "10-20-2016"}] 

然而,當我它看起來更像這樣:

[{CreatedBy: "John Doe", CreatedDate: "10-20-2016",PrimaryID:"3920F0-3434D3-ADF-3SDF"}] 

這是行不通的。我覺得我失去了一些非常明顯的東西。

usedAttributes只是一個包含屬性(列數據)的簡單對象數組。這個想法是用戶可以選擇他們想要獲得的屬性,這樣數據表就非常動態。在這個例子中,usedAttributes可能看起來像這樣:

["CreatedBy": [{Checked:false}],"CreatedDate":[{Checked:true}]] 

因此,用戶希望看到這兩個屬性,儘管更多的存在。

+0

可以顯示'usedAttributes'以及它如何與這個? – Claies

回答

1

你可以做到這一點,

<div ng-controller="listController"> 
    <table class="table table-striped"> 
     <thead> 
     <tr> 
      <th ng-repeat="(key, value) in tabularData[0]">{{key | uppercase }} 
      </th> 
     </tr> 
     <tbody> 
      <tr ng-repeat="val in tabularData"> 
      <td ng-repeat="cell in val"> 
       <input type="text" ng-model="cell"> 
      </td> 
      </tr> 
     </tbody> 
    </table> 
    </div> 

DEMO