日期的顺序列表如何从对象获取

How order list of dates get from object

本文关键字:对象 获取 顺序 列表 日期      更新时间:2023-09-26

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

     // 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";
          }
         }

在 HTML 中:

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

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

我不知道

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

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>