1
我想製作可排序的表。我寫了下面的視圖和控制器:我的示波器功能不運行在angularjs
查看:
<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" }
];
}
當我點擊山坳umn標題沒有任何反應。我發現了一些東西,那就是當我將ng-click="sort('{{metadata.columnProperty}}')"
更改爲ng-click="sort('firstName')"
時,我點擊每一列的標題就排序第一列。