NG -Table示例的说明

时间:2014-11-06 14:02:20

标签: javascript angularjs

有人可以解释这个例子

Plunker NG-Table

在HTML中,有 - >

<tbody ng-repeat="group in $groups">

但在js中没有原因?

  

$组

1 个答案:

答案 0 :(得分:2)

ngTable module在指定groupBy ngTableParameter(you can see it in the github source code here )时定义$ scope。$ groups。

$scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10          // count per page
}, {
    groupBy: 'role',   // << ----- grouping parameter
    total: data.length,
    getData: function($defer, params) {
        var orderedData = params.sorting() ?
                $filter('orderBy')(data, $scope.tableParams.orderBy()) :
                data;

        $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
    }
});

这是由ngTable在$ scope上创建的$ groups,用于plunker示例中的数据。

$scope.$groups = [
            {
                value: 'Administrator',
                data: [
                    {name: "Moroni", age: 50, role: 'Administrator'},
                    {name: "Tiancum", age: 43, role: 'Administrator'},
                    {name: "Jacob", age: 27, role: 'Administrator'}
                ]
            },
            {
                value: 'Moderator',
                data: [
                    {name: "Nephi", age: 29, role: 'Moderator'},
                    {name: "Nephi", age: 29, role: 'Moderator'},
                    {name: "Tiancum", age: 43, role: 'Moderator'},
                    {name: "Enos", age: 34, role: 'Moderator'}
                ]
            },
            {
                value: 'User',
                data: [
                    {name: "Enos", age: 34, role: 'User'},
                    {name: "Tiancum", age: 43, role: 'User'},
                    {name: "Jacob", age: 27, role: 'User'},
                    {name: "Enos", age: 34, role: 'User'},
                    {name: "Jacob", age: 27, role: 'User'},
                    {name: "Nephi", age: 29, role: 'User'},
                    {name: "Tiancum", age: 43, role: 'User'},
                    {name: "Jacob", age: 27, role: 'User'},
                    {name: "Nephi", age: 29, role: 'User'},
                    {name: "Enos", age: 34, role: 'User'}
                ]
            }
        ]