如何删除 ng-repeat 的默认顺序 [英] How to remove default order of ng-repeat
本文介绍了如何删除 ng-repeat 的默认顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在动态表数据的 ng-repeat 中停止默认排序?目前我收到以下订单:
地址 |客户 ID |姓名
但我想要的是低于排序:
客户 ID |姓名 |地址
如果有任何帮助,我将不胜感激.
JS:
app.controller('MyController', function ($scope) {$scope.Customers = [{ CustomerId: 1, Name: "John Hammond", Addr:'India'},{CustomerId: 2, Name: "Mudassar Khan", Addr:'India'},{CustomerId: 3, Name: "Suzanne Mathews", Addr:'India'},{CustomerId: 4, Name: "Robert Schidner", Addr: 'India'}];});
HTML:
<tr ><th ng-repeat="(key,value) in Customers[0]">{{key}}</th></tr><tbody ng-repeat="c in 客户"><tr></tr></tbody>
解决方案
试试下面的方法.我希望下面的片段结果显示了您想要的内容.
angular.module("aaa",[]).controller('MyController', function ($scope) {$scope.Customers = [{ CustomerId: 1, Name: "John Hammond", Addr:'India'},{CustomerId: 2, Name: "Mudassar Khan", Addr:'India'},{CustomerId: 3, Name: "Suzanne Mathews", Addr:'India'},{CustomerId: 4, Name: "Robert Schidner", Addr: 'India'}];$scope.keys = Object.keys($scope.Customers[0]);});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><div ng-app="aaa" ng-controller="MyController"><表格><tr><th ng-repeat="key in keys">{{钥匙}}</th></tr><tbody ng-repeat="c in 客户"><tr><td ng-repeat="key in keys">{{c[key]}}</td></tr></tbody>
How do I stop default sorting inside the ng-repeat for dynamic table data ?
Currently I am getting below order:
Addr | CustomerId | Name
but what I want is below ordering:
CustomerId | Name | Addr
Any Help would me much appreciated.
JS:
app.controller('MyController', function ($scope) {
$scope.Customers = [
{ CustomerId: 1, Name: "John Hammond", Addr:'India'
},
{
CustomerId: 2, Name: "Mudassar Khan", Addr:'India'
},
{
CustomerId: 3, Name: "Suzanne Mathews", Addr:'India'
},
{
CustomerId: 4, Name: "Robert Schidner", Addr: 'India'
}
];
});
HTML:
<table>
<tr >
<th ng-repeat="(key,value) in Customers[0]">{{key}}</th>
</tr>
<tbody ng-repeat="c in Customers">
<tr>
</tr>
</tbody>
</table>
解决方案
Try this below way. I hope this below snippet result is showing what you want.
angular.module("aaa",[]).controller('MyController', function ($scope) {
$scope.Customers = [
{ CustomerId: 1, Name: "John Hammond", Addr:'India'
},
{
CustomerId: 2, Name: "Mudassar Khan", Addr:'India'
},
{
CustomerId: 3, Name: "Suzanne Mathews", Addr:'India'
},
{
CustomerId: 4, Name: "Robert Schidner", Addr: 'India'
}
];
$scope.keys = Object.keys($scope.Customers[0]);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="aaa" ng-controller="MyController">
<table>
<tr>
<th ng-repeat="key in keys">
{{key}}
</th>
</tr>
<tbody ng-repeat="c in Customers">
<tr>
<td ng-repeat="key in keys">{{c[key]}}</td>
</tr>
</tbody>
</table>
</div>
这篇关于如何删除 ng-repeat 的默认顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文