У меня есть этот объект, возвращенный мне через angular Наблюдаемый HttpClient.
{
"jsonrpc": "2.0",
"result": [
{
"event": {
"id": "29688772",
"name": "Demoliner/Middelkoop v Behar/Escobar",
"countryCode": "AR",
"timezone": "UTC",
"openDate": "2020-02-08T20:00:00.000Z"
},
"marketCount": 1
},
{
"event": {
"id": "29691591",
"name": "Bemelmans v Pellegrino",
"countryCode": "FR",
"timezone": "UTC",
"openDate": "2020-02-09T09:00:00.000Z"
},
"marketCount": 1
},
{
"event": {
"id": "29690566",
"name": "Diez v Emil Ruusuvuori",
"countryCode": "NL",
"timezone": "UTC",
"openDate": "2020-02-08T13:14:00.000Z"
},
"marketCount": 1
},
{
"event": {
"id": "29690822",
"name": "Koepfer v J Rodionov",
"countryCode": "US",
"timezone": "UTC",
"openDate": "2020-02-08T18:00:00.000Z"
},
"marketCount": 1
},
{
"event": {
"id": "29691586",
"name": "Basic v Vanni",
"countryCode": "FR",
"timezone": "UTC",
"openDate": "2020-02-09T09:00:00.000Z"
},
"marketCount": 1
},
{
"event": {
"id": "29691596",
"name": "P Kotov v Mayot",
"countryCode": "FR",
"timezone": "UTC",
"openDate": "2020-02-09T09:00:00.000Z"
},
"marketCount": 1
}
Я хочу отсортировать массив по openDate.
Я думал сделать это в подписка вроде так
getTennisMatches() {
this.betfairService.getTennisMatches().subscribe((data: any[]) => {
this.matches = data;
this.sortedMatches = this.matches.sort((a, b) => (a.result.event.openDate > b.result.event.openDate) ? 1 : -1);
// OR
this.sortedMatches = _.sortBy(this.matches.result, o => o.result.event.openDate);
});
}
Оба метода сортировки не работают с ошибками this.matches.sort is not a function
для ванили или Cannot read property 'event' of undefined
для loda sh
Я думаю, что я приходится перебирать события, но я не уверен, что делаю. Я использую loda sh, потому что мне проще понять его синтаксис, но мне не нужно его использовать. Спасибо