javascript - In js ist das JSON-Objektarray nach Objekteigenschaften sortiert.
ringa_lee
ringa_lee 2017-05-19 10:39:47
0
1
605
[
    {
        "flightId": "",
        "segments": [
            {
                "flightCode": "007",
                "flightDurationInMinutes": 120,
                "transitDurationInMinutes": 30,
                "seatType": 2,
                "departureDetail": {
                    "airportCode": "BJ",
                    "airPortName": "北京首都机场",
                    "date": "2017-04-06",
                    "time": "20:01:00",
                    "departureTerminal": "T3",
                    "city": {
                        "name": "城市名称",
                        "code": "城市编码",
                        "airPorts": [
                            {
                                "name": "",
                                "code": ""
                            },
                            {
                                "name": "",
                                "code": ""
                            }
                        ]
                    }
                },
                "arrivalDetail": {
                    "airportCode": "BJ",
                    "airPortName": "北京首都机场",
                    "date": "2017-04-06",
                    "time": "20:01:00",
                    "departureTerminal": "T3",
                    "city": {
                        "name": "城市名称",
                        "code": "城市编码",
                        "airPorts": [
                            {
                                "name": "",
                                "code": ""
                            },
                            {
                                "name": "",
                                "code": ""
                            }
                        ]
                    }
                },
                "stopInfo": {
                    "airportCode": "ABC",
                    "durationMinutes": 30
                },
                "marketingAirline": {
                    "name": "市场航司名称",
                    "code": "市场航司二字码",
                    "logoUrl": " 航司logo地址"
                },
                "operatingAirline": {
                    "name": "操作航司名称",
                    "code": "操作航司二字码",
                    "logoUrl": " 航司logo地址"
                }
            }
        ],
        "departureDetail": {
            "airportCode": "BJ",
            "airPortName": "北京首都机场",
            "date": "2017-04-06",
            "time": "20:01:00",
            "departureTerminal": "T3",
            "city": {
                "name": "",
                "code": "",
                "airPorts": [
                    {
                        "name": "",
                        "code": ""
                    },
                    {
                        "name": "",
                        "code": ""
                    }
                ]
            }
        },
        "arrivalDetail": {
            "airportCode": "BJ",
            "airPortName": "北京首都机场",
            "date": "2017-04-06",
            "time": "20:01:00",
            "departureTerminal": "T3",
            "city": {
                "name": "",
                "code": "",
                "airPorts": [
                    {
                        "name": "",
                        "code": ""
                    },
                    {
                        "name": "",
                        "code": ""
                    }
                ]
            }
        },
        "transitCityCodeList": [
            "1",
            "2",
            "3"
        ],
        "transitAirportCodeList": [
            "CNY",
            "TTY"
        ],
        "numberOfTransits": 1,
        "journeyDuration": 110,
        "seatType": 1,
        "fareInfo": {
            "partnerFare": {
                "currency": "币种",
                "totalFare": 58000000,
                "adultFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "childFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "infantFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                }
            },
            "airlineFare": {
                "currency": "币种",
                "totalFare": 58000000,
                "adultFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "childFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "infantFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                }
            }
        },
        "baggage": {
            "baggageType": "件、kg",
            "count": 10,
            "currency": "币种",
            "price": 15.58,
            "flightId": ""
        }
    },
    {
        "flightId": "",
        "segments": [
            {
                "flightCode": "007",
                "flightDurationInMinutes": 180,
                "transitDurationInMinutes": 30,
                "seatType": 2,
                "departureDetail": {
                    "airportCode": "BJ",
                    "airPortName": "北京首都机场",
                    "date": "2017-04-06",
                    "time": "20:01:00",
                    "departureTerminal": "T3",
                    "city": {
                        "name": "城市名称",
                        "code": "城市编码",
                        "airPorts": [
                            {
                                "name": "",
                                "code": ""
                            },
                            {
                                "name": "",
                                "code": ""
                            }
                        ]
                    }
                },
                "arrivalDetail": {
                    "airportCode": "BJ",
                    "airPortName": "北京首都机场",
                    "date": "2017-04-06",
                    "time": "20:01:00",
                    "departureTerminal": "T3",
                    "city": {
                        "name": "城市名称",
                        "code": "城市编码",
                        "airPorts": [
                            {
                                "name": "",
                                "code": ""
                            },
                            {
                                "name": "",
                                "code": ""
                            }
                        ]
                    }
                },
                "stopInfo": {
                    "airportCode": "ABC",
                    "durationMinutes": 30
                },
                "marketingAirline": {
                    "name": "市场航司名称",
                    "code": "市场航司二字码",
                    "logoUrl": " 航司logo地址"
                },
                "operatingAirline": {
                    "name": "操作航司名称",
                    "code": "操作航司二字码",
                    "logoUrl": " 航司logo地址"
                }
            }
        ],
        "departureDetail": {
            "airportCode": "BJ",
            "airPortName": "北京首都机场",
            "date": "2017-04-06",
            "time": "20:01:00",
            "departureTerminal": "T3",
            "city": {
                "name": "",
                "code": "",
                "airPorts": [
                    {
                        "name": "",
                        "code": ""
                    },
                    {
                        "name": "",
                        "code": ""
                    }
                ]
            }
        },
        "arrivalDetail": {
            "airportCode": "BJ",
            "airPortName": "北京首都机场",
            "date": "2017-04-06",
            "time": "20:01:00",
            "departureTerminal": "T3",
            "city": {
                "name": "",
                "code": "",
                "airPorts": [
                    {
                        "name": "",
                        "code": ""
                    },
                    {
                        "name": "",
                        "code": ""
                    }
                ]
            }
        },
        "transitCityCodeList": [
            "1",
            "2",
            "3"
        ],
        "transitAirportCodeList": [
            "CNY",
            "TTY"
        ],
        "numberOfTransits": 2,
        "journeyDuration": 110,
        "seatType": 1,
        "fareInfo": {
            "partnerFare": {
                "currency": "币种",
                "totalFare": 58000000,
                "adultFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "childFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "infantFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                }
            },
            "airlineFare": {
                "currency": "币种",
                "totalFare": 58000000,
                "adultFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "childFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "infantFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                }
            }
        },
        "baggage": {
            "baggageType": "件、kg",
            "count": 10,
            "currency": "币种",
            "price": 15.58,
            "flightId": ""
        }
    },
    {
        "flightId": "",
        "segments": [
            {
                "flightCode": "007",
                "flightDurationInMinutes": 240,
                "transitDurationInMinutes": 30,
                "seatType": 2,
                "departureDetail": {
                    "airportCode": "BJ",
                    "airPortName": "北京首都机场",
                    "date": "2017-04-06",
                    "time": "20:01:00",
                    "departureTerminal": "T3",
                    "city": {
                        "name": "城市名称",
                        "code": "城市编码",
                        "airPorts": [
                            {
                                "name": "",
                                "code": ""
                            },
                            {
                                "name": "",
                                "code": ""
                            }
                        ]
                    }
                },
                "arrivalDetail": {
                    "airportCode": "BJ",
                    "airPortName": "北京首都机场",
                    "date": "2017-04-06",
                    "time": "20:01:00",
                    "departureTerminal": "T3",
                    "city": {
                        "name": "城市名称",
                        "code": "城市编码",
                        "airPorts": [
                            {
                                "name": "",
                                "code": ""
                            },
                            {
                                "name": "",
                                "code": ""
                            }
                        ]
                    }
                },
                "stopInfo": {
                    "airportCode": "ABC",
                    "durationMinutes": 30
                },
                "marketingAirline": {
                    "name": "市场航司名称",
                    "code": "市场航司二字码",
                    "logoUrl": " 航司logo地址"
                },
                "operatingAirline": {
                    "name": "操作航司名称",
                    "code": "操作航司二字码",
                    "logoUrl": " 航司logo地址"
                }
            }
        ],
        "departureDetail": {
            "airportCode": "BJ",
            "airPortName": "北京首都机场",
            "date": "2017-04-06",
            "time": "20:01:00",
            "departureTerminal": "T3",
            "city": {
                "name": "",
                "code": "",
                "airPorts": [
                    {
                        "name": "",
                        "code": ""
                    },
                    {
                        "name": "",
                        "code": ""
                    }
                ]
            }
        },
        "arrivalDetail": {
            "airportCode": "BJ",
            "airPortName": "北京首都机场",
            "date": "2017-04-06",
            "time": "20:01:00",
            "departureTerminal": "T3",
            "city": {
                "name": "",
                "code": "",
                "airPorts": [
                    {
                        "name": "",
                        "code": ""
                    },
                    {
                        "name": "",
                        "code": ""
                    }
                ]
            }
        },
        "transitCityCodeList": [
            "1",
            "5",
            "6"
        ],
        "transitAirportCodeList": [
            "CNY",
            "TTY",
            "YYY"
        ],
        "numberOfTransits": 3,
        "journeyDuration": 110,
        "seatType": 1,
        "fareInfo": {
            "partnerFare": {
                "currency": "币种",
                "totalFare": 48000000,
                "adultFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "childFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "infantFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                }
            },
            "airlineFare": {
                "currency": "币种",
                "totalFare": 48000000,
                "adultFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "childFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                },
                "infantFare": {
                    "baseFare": 0.24,
                    "tax": 0.05,
                    "totalFee": 12.8
                }
            }
        },
        "baggage": {
            "baggageType": "件、kg",
            "count": 10,
            "currency": "币种",
            "price": 15.58,
            "flightId": ""
        }
    }
]

this.searchResult.sort(util.getSortFun('desc','journeyDuration'));

getSortFun: function(order, sortBy){

var ordAlpah = (order == 'asc') ? '>' : '<';
var sortFun = new Function('a', 'b', 'return a.' + sortBy + ordAlpah + 'b.' + sortBy + '?1:-1');
return sortFun;

}

Die Sortierung war erfolgreich, aber ich habe nach Gesamtpreis sortiert und das Ergebnis wurde nicht erfolgreich sortiert

ringa_lee
ringa_lee

ringa_lee

Antworte allen(1)
给我你的怀抱

underscore
调用sortBy

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage