具有复杂orderBy的Angular-js ng-repeat

时间:2015-10-26 16:44:34

标签: javascript angularjs angularjs-ng-repeat angularjs-orderby

-------编辑问题-----

我需要使用orderBy with limitTo:

示例:

orderBy id limitTo 1

'adam1 @ xxx' - id:10

'adam2 @ xxx' - id:20

'adam3 @ xx' - id:16

我需要再次通过id订购

'adam1 @ xxx' - id:10

'adam3 @ xx' - id:16

'adam2 @ xxx' - id:20

http://jsfiddle.net/WRtqV/924/

function MyCtrl($scope) {
    $scope.limit = 1;
    $scope.itemsMsg = [
        {
        'adam1@xxx': [{
            id: 10,
            content: 'test1',
            cod: 25
        }, {
            id: 11,
            content: 'test2',
            cod: 13
        }, {
            id: 12,
            content: 'test3',
            cod: 10
        }]
    }, {
        'adam2@xxx': [{
            id: 20,
            content: 'test4',
            cod: 24
        }, {
            id: 21,
            content: 'test5',
            cod: 23
        }, {
            id: 30,
            content: 'test6',
            cod: 20
        }]
    }, {
        'adam3@xx': [{
            id: 16,
            content: 'xxx',
            cod: 1
        }]
    }];
    
 
    
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-controller="MyCtrl">
    <div ng-repeat="item in itemsMsg">
        <ul ng-repeat="(key, value) in item">
            <li ng-repeat="obj in value | orderBy:id | limitTo: limit">{{obj.id}} :{{obj.cod}} : {{obj.content}}</li>
        </ul>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

尝试下面的代码: 它按id排序,然后按优先级排序:

<div ng-repeat="item in itemsMsg | orderBy:['id','code']"></div>