简体   繁体   English

使用ng-repeat保持表中的一列相同

[英]Keeping one column in a table using ng-repeat the same

I have a table that is pulling data from a json file and populating td with ng-repeat. 我有一个表,该表从json文件中提取数据并用ng-repeat填充td。 However, I want my first column (Line #) to stay the same. 但是,我希望第一列(行号)保持不变。 For example just 1,2,3,4 to represent which phone line the customer is on, and the rest of the data to be populated with the ng-repeat. 例如,仅1,2,3,4表示客户使用的电话线,其余数据将使用ng-repeat填充。 I've been researching and have not been able to find anything any help is appreciated. 我一直在研究,却找不到任何帮助。 Code is below. 代码如下。

        <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's ng-repeat exposes an $index property that will return the current index of the array. Angular的ng-repeat公开了一个$index属性,该属性将返回数组的当前索引。 So your HTML could look like: 因此,您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM