2016-02-23 21 views
0

我有一个表格从json文件中提取数据并用ng-repeat填充td。但是,我希望我的第一列(行号)保持不变。例如,只有1,2,3,4代表客户所在的电话线路,其余数据将用ng-repeat填充。我一直在研究,一直没能找到任何帮助表示赞赏。代码如下。使用ng保留表中的一列 - 重复相同

 <tr> 
      <th>Line #</th> 
      <th>Name</th> 
      <th>Phone #</th> 
      <th>Range</th> 
     </tr> 
     <tr ng-repeat="customer in customers | orderBy: 'id' | limitTo: 4" ng-class="{ 'alert-danger' : customer.in == 'no', 'alert-success' : customer.in == 'yes', 'alert-warning' : customer.in == 'unknown' }"> 
      <td>1</td> 
      <td>{{customer.name}}</td> 
      <td>{{customer.phoneNumber}}</td> 
      <td>{{customer.in}}</td> 
     </tr> 
    </table> 
    <div class="modal-close" ng-click="toggleModal()">X</div> 
</div> 

回答

0

角的ng-repeat公开的$index属性,将返回数组的当前索引。所以你的HTML可能看起来像:

<tr ng-repeat="customer in customers | orderBy: 'id' | limitTo: 4" ng-class="{ 'alert-danger' : customer.in == 'no', 'alert-success' : customer.in == 'yes', 'alert-warning' : customer.in == 'unknown' }"> 
     <td>{{$index + 1}}</td> 
     <td>{{customer.name}}</td> 
     <td>{{customer.phoneNumber}}</td> 
     <td>{{customer.in}}</td> 
    </tr> 
+0

这很完美,非常感谢。 – TanessiaG

相关问题