目前,我没有任何可能通过使用orderBy
-filter来排序列表中的列。问题是我有一个嵌套的ngRepeat。嵌套ng-repeat中的列排序(AngularJS)
查看:
<md-list>
<md-list-item>
<span ng-repeat="item in ::hItems track by $index" ng-click="sortBy(item)" flex>
{{ ::item }}
</span>
</md-list-item>
<md-divider></md-divider>
<md-list-item ng-repeat="cItem in ::cItems | orderBy:sortType:sortReverse track by $index">
<span ng-repeat="(key, value) in ::cItem track by $index" flex>
{{ ::value }}
</span>
<md-divider></md-divider>
</md-list-item>
</md-list>
只要列上的用户点击标题功能sortBy
将被调用。该功能在控制器中实现如下:
//Default values:
$scope.sortType = 'NAME';
$scope.sortReverse = false;
var orderBy = $filter('orderBy');
//sortBy func:
function sortBy(columnKey) {
$scope.sortType = columnKey;
$scope.sortReverse = !$scope.sortReverse;
$scope.cItems = orderBy($scope.cItems, $scope.sortType, $scope.sortReverse);
}
该列表仅排序为默认值name
。这里是GET请求的阵列输出:
//JSON data
[
{
"ArtNo": "DE123",
"SHORTCODE": "ABC",
"NAME": "article one",
"QUANTITY": 3,
"GROUPID": 1,
"ACTIVE": 1
},...
]
所以,我需要,因为你可以看到如何在阵列与琴键号和对象值=>[0:Object, 1:Object...]
定义嵌套ngRepeat。我只需要一个解决方案为我的sortBy
功能。有没有人有想法?
以下是我的输出列表:
ArtNo | SHORTCODE | NAME | QUANTITY
DE123 | ABC001 | article one | 3
DE456 | ABC002 | article two | 8
DE789 | ABC003 | article three | 4
DE321 | ABC004 | article four | 13
....
请简化您的问题代码并提供一个工作小提琴... –
@EliasSoares您在我的代码中不理解什么?然后我可以编辑我的线程。 – yuro
什么是'md-list','md-list-item','md-divider'?我知道这可能对问题没有影响,但是当您提供问题发生的最小代码时,您(和我们)很容易找到问题。 –