【问题标题】:Angular-js ng-repeat with complex orderBy [duplicate]具有复杂顺序的Angular-js ng-repeat[重复]
【发布时间】:2016-01-25 20:52:00
【问题描述】:

-------已编辑的问题-----

我需要将 orderBy 与 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>

【问题讨论】:

  • 我需要使用 orderBy 和 limitTo

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多