2016-02-28 162 views
1

我認爲在角度上使用orderby過濾器,我們可以簡單地通過在您要排序的那個之前添加「 - 」來反轉。所以在我的情況下,下面的代碼,爲什麼這不起作用?我已經嘗試過用「 - 」進出單引號。按降序進行角度排序

代碼:

<tr class="alertText" ng-repeat="swipe in ppt.Swipes | orderBy:'-swipe.date' "> 
    <td>{{swipe.date|date : 'MM/dd/yyyy'}}</td> 
    <td>{{swipe.descr}}</td> 
    <td>{{swipe.amount | currency}}</td> 
    <td>{{swipe.dueDate|date : 'MM/dd/yyyy'}}</td> 
    <td>{{swipe.status}}</td> 
    <td class="clearIcon"><span ng-click="editSwipe()"><img src="ppt/assets/toolIcons/clearswipe-small.svg"></span></td> 
</tr> 

回答

2

orderBy:'-date'是足夠多的訂購

2

你應該具備的使用性能,如在filter的NG-重複 '-date',

代碼:

<div ng-repeat="card in myCards | orderBy:'-date'"> 
     <businesscard>{{card.firstName}} {{card.date | date}}</businesscard> 
    </div> 

這裏是工作jsfiddle

2

function Main($scope) { 
 
    $scope.items = [ 
 
     {"name":"ali",date: new Date('12/23/2013')} 
 
     ,{"name":"Reza",date: new Date('12/23/2015')}, 
 
     {"name":"Amir",date: new Date('12/23/2011')} 
 
    ]; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app> 
 
    <div ng-controller="Main"> 
 
     <div ng-repeat="item in items | orderBy:'-date'">{{item.name}}: {{item.date | date}}</div> 
 
    </div> 
 
</div>

1

而且不要忘記比你可以使用排序依據過濾器的第二個參數來設置排序順序:

<tr class="alertText" ng-repeat="swipe in ppt.Swipes | orderBy:'date':1">