[英]Keeping one column in a table using ng-repeat the same
我有一個表,該表從json文件中提取數據並用ng-repeat填充td。 但是,我希望第一列(行號)保持不變。 例如,僅1,2,3,4表示客戶使用的電話線,其余數據將使用ng-repeat填充。 我一直在研究,卻找不到任何幫助。 代碼如下。
<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>
Angular的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.