日期的订单列表如何从对象获得

时间:2016-02-11 09:57:02

标签: javascript angularjs ionic-framework sql-order-by

我有按日期排序的列表,我想通过点击按钮重新排序。这个日期来自一个对象,我尝试这个代码,但它的排序就像一个简单的数字:

     // function to order and change button by click
         $scope.sortType = "CreationDate";
         $scope.sortReverse = false;
         $scope.buttonStyle = "icon ion-ios-time-outline";
         $scope.buttonPress = false;
         $scope.ordina = function() {

          if ($scope.sortType == "CreationDate") {
           $scope.sortReverse = !$scope.sortReverse;
           console.log("riordinate");
          }

          $scope.buttonPress = !$scope.buttonPress;
          if ($scope.buttonPress == true) {
           $scope.buttonStyle = "icon ion-ios-time";
          } else {
           $scope.buttonStyle = "icon ion-ios-time-outline";
          }
         }

in html:

<ion-item ng-repeat="object in allODA | filter: searchQuery | orderBy : sortType : sortReverse " href="#/app/ODA_Detail/{{object.caseTaskId}}">

任何解决方案???想法???

1 个答案:

答案 0 :(得分:0)

我不知道我是否理解正确,但这是一个用日期对表格进行排序的示例,单击列标题对其进行排序。

https://jsfiddle.net/lisapfisterer/8pvqau4z/

这不使用离子,你可能需要调整它。

<table class="table table-striped">
    <thead>
        <td data-ng-click="sortType = name; sortReverse = !sortReverse;">
            Date
        </td>
        <td data-ng-click="sortType = name; sortReverse = !sortReverse;">
            Name
        </td>
    </thead>
    <tbody>
        <tr ng-repeat="item in allItems | orderBy:sortType:sortReverse">
            <td>{{item.date | date:"yyyy-MM-dd"}}</td>
            <td>{{item.name}}</td>
        </tr>
    </tbody>
</table>
相关问题