1

我正在尝试制作可排序的表。我写了以下视图和控制器:

看法:

<div class="container" ng-app>
<div ng-controller="SortableTblCtrl">
    <table class="table table-hover table-bordered span12">
        <tr>
            <th ng-repeat="metadata in metadatas" ng-click="sort('{{metadata.columnProperty}}')" style="cursor: pointer">{{metadata.columnName}} </th>
        </tr>
        <tr ng-repeat="person in persons | orderBy:predicate:reverse">
            <td>{{person.firstName}}</td>
            <td>{{person.lastName}}</td>
        </tr>
    </table>
</div>

控制器:

function SortableTblCtrl($scope) {
$scope.persons = [
    { "firstName": "firstname1", "lastName": "lastname1" },
    { "firstName": "firstname2", "lastName": "lastname2" },
    { "firstName": "firstname3", "lastName": "lastname3" }
];
$scope.predicate = "";
$scope.reverse = false;

$scope.sort = function (pred) {
    $scope.predicate = pred;
    $scope.reverse = !$scope.reverse;
};

$scope.metadatas = [
    { "columnProperty": "firstName", "columnName": "First Name" },
    { "columnProperty": "lastName", "columnName": "Last Name" }
];

}

当我单击列标题时,没有任何反应。我发现了一些东西,那就是当我单击每个列标题时,我将其更改ng-click="sort('{{metadata.columnProperty}}')"为对第一列进行排序。ng-click="sort('firstName')"

4

1 回答 1

1

这:ng-click="sort('{{metadata.columnProperty}}')"应该是ng-click="sort(metadata.columnProperty)"

于 2013-03-01T14:59:29.200 回答