orderBy不适用于角度js中的嵌套数组

时间:2015-04-13 08:05:21

标签: angularjs angularjs-filter

在以下情况中,orderBy过滤器不适用于point属性和name。我不知道为什么? here是我在小提琴上的榜样。

模板:

<div ng-controller="AppCtrl">
    <table>
        <tr>
            <th style="width:100px;" ng-click="pred='name'">name</th>
            <th style="width:100px;">id</th>
            <th style="width:100px;" ng-click="pred='points'">point</th>
        </tr>
        <tbody ng-repeat="user in ranking | orderBy:pred">
        <tr ng-repeat="tab in user.tabs | orderBy:pred">
            <td style="width:100px;">{{user.name}}</td>
            <td style="width:100px;">{{tab.tabId}}</td>
            <td style="width:100px;">{{tab.points}}</td>
        </tr>
        </tbody>
    </table> 
</div>

控制器:

var app = angular.module('app', []);

function AppCtrl($scope) {
    $scope.currentTab = 1
    $scope.ranking = [
        {
            'uId': 2,
            'name': 'Jeremy',
            'tabs': [
                {
                    'tabId': 1,
                    'points': 100,
                }, 
                {
                    'tabId': 2,
                    'points': 10
                }
            ],
        },
        {
            'uId': 3,
            'name': 'Jordon',
            'tabs': [
                {
                    'tabId': 1,
                    'points': 180,
                },
                {
                    'tabId': 2,
                    'points': 5
                }
            ],
        }
    ]
}

0 个答案:

没有答案