2016-11-11 54 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