我有一个场景,我需要根据我使用orderBy
过滤器
在这里,我可以完美地按名称排序,但我无法对收视率进行排序,这又是一个数组
HTML:
<table class="friends">
<thead>
<tr class='table-head'>
<th scope="col"><a style="cursor:pointer" ng-click="sortType = 'name'; sortReverse = !sortReverse">Candidate Name</a></th>
<th scope="col" ng-repeat="a in [1,2,3,4]" ><a style="cursor:pointer" ng-click="sortType = 'rating'; sortReverse = !sortReverse">Round{{a}}</a></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="candidate in aCandidateDetails| orderBy:sortType:sortReverse" class="text-center">
<td>
<div>{{candidate.name}}</div>
</td>
<td ng-repeat="candidateData in candidate.ratings| orderBy:sortType:sortReverse">
<div >
{{candidateData.rating}}
</div>
<span ng-if="!candidateData.rating"> - NA - </span> </td>
<td data-title="Status">
<div>{{candidate.interviewStatus}}</div>
</td>
<td><a href="" ng-model='candidate' ng-click="fnCandidateFeedbackDetails(candidate.uniqueId,candidate._id)"><i class="fa fa-info-circle" aria-hidden="true"></i></a></td>
</tr>
</tbody>
</table>
JS:
$scope.sortType = 'name'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
我做了一个有json数据的工作示例
send
答案 0 :(得分:1)
ngRepeat
指令会创建一个孩子 $scope
,因此您应该使用Dot Rule
或controller-as-syntax
:
$scope.model = {};
$scope.model.sortType = 'name';
$scope.model.sortReverse = false;
并修改视图中的所有内容..
请参阅 DEMO