Angular sortBy不按预期排序页面结果,为什么?

时间:2015-01-16 17:11:09

标签: angularjs sorting

我似乎无法使角度sortBy起作用,它不能正确排序数据。按价格排序,例如,没有正确地给出最低到最高。谁能看出我做错了什么?数据从后端以价格上升的方式返回,但不按正确的顺序显示。

据我所知,我正在做的一切。

以下是我正在尝试排序的数据示例:

[
    {"Inbound":{"SearchWeight":1,"Duration":5100000,"DurationString":"1h 25m","DepartureDateString":"Sunday 05 Jul 2015","DepartureTimeString":"07:50","DepartureTime":28200000,"DepartAirportName":null,"DepartureIata":"GLA","ArrivalDateString":"Sunday 05 Jul 2015","ArrivalTimeString":"09:15","ArrivalTime":33300000,"ArriveAirportName":null,"ArrivalIata":"LGW","Stops":0,"StopData":"Direct","AirlineName":"EasyJet","AirlineThumbnailUrl":"easyjet","GUID":947178494,"TTResultNumber":"4_37.0","StopInfo":[],"FlightExtras":null,"Price":35.14,"CheapestReturn":0,"NumAdults":2,"NumChildren":0,"NumInfants":0,"Selected":false,"Outbound":false,"BaggageIncluded":false,"ArrivesNextDay":false,"FlightNo":"882","PairOutFlightNo":"883"},"Outbound":{"SearchWeight":1,"Duration":5100000,"DurationString":"1h 25m","DepartureDateString":"Saturday 27 Jun 2015","DepartureTimeString":"08:55","DepartureTime":32100000,"DepartAirportName":null,"DepartureIata":"LGW","ArrivalDateString":"Saturday 27 Jun 2015","ArrivalTimeString":"10:20","ArrivalTime":37200000,"ArriveAirportName":null,"ArrivalIata":"GLA","Stops":0,"StopData":"Direct","AirlineName":"EasyJet","AirlineThumbnailUrl":"easyjet","GUID":947178494,"TTResultNumber":"","StopInfo":[],"FlightExtras":null,"Price":35.14,"CheapestReturn":0,"NumAdults":2,"NumChildren":0,"NumInfants":0,"Selected":false,"Outbound":false,"BaggageIncluded":false,"ArrivesNextDay":false,"FlightNo":"883","PairOutFlightNo":""},"Price":70.28,"TTResultNumber":"4_37.0","DepartureDateString":"Saturday 27 Jun 2015"},

    {"Inbound":{"SearchWeight":1,"Duration":5100000,"DurationString":"1h 25m","DepartureDateString":"Sunday 05 Jul 2015","DepartureTimeString":"07:50","DepartureTime":28200000,"DepartAirportName":null,"DepartureIata":"GLA","ArrivalDateString":"Sunday 05 Jul 2015","ArrivalTimeString":"09:15","ArrivalTime":33300000,"ArriveAirportName":null,"ArrivalIata":"LGW","Stops":0,"StopData":"Direct","AirlineName":"EasyJet","AirlineThumbnailUrl":"easyjet","GUID":1816944519,"TTResultNumber":"4_61.0","StopInfo":[],"FlightExtras":null,"Price":35.14,"CheapestReturn":0,"NumAdults":2,"NumChildren":0,"NumInfants":0,"Selected":false,"Outbound":false,"BaggageIncluded":false,"ArrivesNextDay":false,"FlightNo":"882","PairOutFlightNo":"897"},"Outbound":{"SearchWeight":1,"Duration":5100000,"DurationString":"1h 25m","DepartureDateString":"Sunday 28 Jun 2015","DepartureTimeString":"21:20","DepartureTime":76800000,"DepartAirportName":null,"DepartureIata":"LGW","ArrivalDateString":"Sunday 28 Jun 2015","ArrivalTimeString":"22:45","ArrivalTime":81900000,"ArriveAirportName":null,"ArrivalIata":"GLA","Stops":0,"StopData":"Direct","AirlineName":"EasyJet","AirlineThumbnailUrl":"easyjet","GUID":1816944519,"TTResultNumber":"","StopInfo":[],"FlightExtras":null,"Price":35.14,"CheapestReturn":0,"NumAdults":2,"NumChildren":0,"NumInfants":0,"Selected":false,"Outbound":false,"BaggageIncluded":false,"ArrivesNextDay":false,"FlightNo":"897","PairOutFlightNo":""},"Price":70.28,"TTResultNumber":"4_61.0","DepartureDateString":"Sunday 28 Jun 2015"},

    {"Inbound":{"SearchWeight":1,"Duration":5100000,"DurationString":"1h 25m","DepartureDateString":"Sunday 05 Jul 2015","DepartureTimeString":"07:50","DepartureTime":28200000,"DepartAirportName":null,"DepartureIata":"GLA","ArrivalDateString":"Sunday 05 Jul 2015","ArrivalTimeString":"09:15","ArrivalTime":33300000,"ArriveAirportName":null,"ArrivalIata":"LGW","Stops":0,"StopData":"Direct","AirlineName":"EasyJet","AirlineThumbnailUrl":"easyjet","GUID":851384341,"TTResultNumber":"4_53.0","StopInfo":[],"FlightExtras":null,"Price":36.785,"CheapestReturn":0,"NumAdults":2,"NumChildren":0,"NumInfants":0,"Selected":false,"Outbound":false,"BaggageIncluded":false,"ArrivesNextDay":false,"FlightNo":"882","PairOutFlightNo":"895"},"Outbound":{"SearchWeight":1,"Duration":5100000,"DurationString":"1h 25m","DepartureDateString":"Sunday 28 Jun 2015","DepartureTimeString":"19:45","DepartureTime":71100000,"DepartAirportName":null,"DepartureIata":"LGW","ArrivalDateString":"Sunday 28 Jun 2015","ArrivalTimeString":"21:10","ArrivalTime":76200000,"ArriveAirportName":null,"ArrivalIata":"GLA","Stops":0,"StopData":"Direct","AirlineName":"EasyJet","AirlineThumbnailUrl":"easyjet","GUID":851384341,"TTResultNumber":"","StopInfo":[],"FlightExtras":null,"Price":36.785,"CheapestReturn":0,"NumAdults":2,"NumChildren":0,"NumInfants":0,"Selected":false,"Outbound":false,"BaggageIncluded":false,"ArrivesNextDay":false,"FlightNo":"895","PairOutFlightNo":""},"Price":73.57,"TTResultNumber":"4_53.0","DepartureDateString":"Sunday 28 Jun 2015"}
]

这是我的ng-repeatfilter : searchFilter似乎没有影响它):

<div data-ng-repeat="flight in filteredResults | filter : searchFilter | startFrom:(currentPage - 1)*10 | orderBy:sortOrder | limitTo:10 " class="flight-results-container">

我的控制器的相关代码:

  $scope.sortOrder = '-Price';

  $scope.filters = [
      { name: 'Price - Lowest to Highest', value: '-Price'},
      { name: 'Price - Highest to Lowest', value: 'Price'},
      { name: 'Duration - Longest to Shortest', value: "-Outbound.Duration+Inbound.Duration"},
      { name: 'Duration - Shortest to Longest', value: "Outbound.Duration+Inbound.Duration"},
      { name: 'Departure - Latest to Earliest', value: "-Outbound.DepartureTime"},
      { name: 'Departure - Earliest to Latest', value: "Outbound.DepartureTime"}
  ]

我的代码创建了过滤器选项:

        <label class="sub-filter--dropdown">
            <span class="sub-filter--title">Sort by</span>
            <select ng-model="sortOrder" class="dropdown-select">
                <option ng-repeat="filter in filters" value="{{filter.value}}">{{filter.name}}</option>
                <option style="display:none" value="">Select A Filter</option>
            </select>
        </label>

0 个答案:

没有答案