如何停止动态表数据的ng-repeat内的默认排序?
目前我的订单低于订单:
地址| CustomerId |名称
但我想要的是下面的订购:
CustomerId |名称|地址
任何帮助都非常感谢。
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>
答案 0 :(得分:1)
请尝试以下方法。我希望下面的代码段显示您想要的内容。
override var constant: CGFloat {
set {
super.constant = newValue
}
get {
return topConstraintConstant()
}
}
fileprivate func topConstraintConstant() -> CGFloat {
if #available(iOS 11.0, *) {
return 0
}else {
return -20
}
}
&#13;
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]);
});
&#13;
答案 1 :(得分:0)
JS中的对象本质上是无序的。您可以做的只是对标题中的键进行硬编码,如果该字符串将针对该特定表进行修复,然后按相应的顺序打印值。
这样的事情:
<table>
<tr >
<th>CustomerId</th>
<th>Name</th>
<th>Addr</th>
</tr>
<tbody>
<tr ng-repeat="c in Customers">
<td>{{CustomerId}}</td>
<td>{{Name}}</td>
<td>{{c.Addr}}</td>
</tr>
</tbody>
</table>
注意:我把ng-repeat放在tr上,这可能是你需要的。我不认为你应该把它放在tbody上。
答案 2 :(得分:0)
您的意思是数据的排序顺序还是列的显示顺序?
接受的答案按照指定的列顺序显示数据,但如果您希望数据本身已排序,则只需向数据添加过滤器,如下所示:
<tbody ng-repeat="c in Customers|orderBy:['CustomerId','Name','Addr']">
这将按指定的字段对列表中的实际数据进行排序。