我正在尝试使用角度对我的列进行排序。我有角度教程的代码可以工作。
现在我很难让一排始终保持在顶部。例如,我将有一列称为 mainContact。此值只能设置一个人为真。我希望 mainContact 为 true 的人始终留在表格的第一行,而其他人则随着排序而变化。老实说,我对如何做到这一点的想法有点迷茫。
我把它放在一起来展示我到目前为止所拥有的:http: //jsfiddle.net/Beastwood/m44fy1j5/
<div ng-controller="ExampleController">
<pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre>
<table class="friend">
<tr>
<th><a href="" ng-click="predicate = 'name'; reverse=false">Name</a></th>
<th><a href="" ng-click="predicate = 'phone'; reverse=!reverse">Phone Number</a></th>
<th><a href="" ng-click="predicate = 'age'; reverse=!reverse">Age</a></th>
<th>MAIN CONTACT</th>
</tr>
<tr ng-repeat="friend in friends | orderBy:predicate:reverse">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
<td>{{friend.age}}</td>
<td>{{friend.mainContact}}</td>
</tr>
</table>
</div>
JS文件
var myApp = angular.module('myApp', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.friends =
[{name:'John', phone:'555-1212', age:10, mainContact:true},
{name:'Mary', phone:'555-9876', age:19, mainContact:false},
{name:'Mike', phone:'555-4321', age:21, mainContact:false},
{name:'Adam', phone:'555-5678', age:35, mainContact:false},
{name:'Julie', phone:'555-8765', age:29, mainContact:false}];
$scope.predicate = '-age';
}]);