如何在amphtml中的过滤下拉列表中对结果进行排序?

时间:2019-05-29 11:23:29

标签: amp-html

我有一个航班预订表,其中包含典型的“发件人”和“发件人”国家。从JSON端点加载的国家/地区列表,格式如下:

airportList": [
  {
    "countryName": "Finland",
    "airportName": "Helsinki Vantaa",
    "airportCode": "HEL",
    "cityName": "Helsinki",
    "countryCode": "FI",
    "cityCode": "HEL"
  },
  {...},
  {...}
]

例如,在“发件人”字段中输入“ sin”时,将过滤JSON并在下拉列表中显示建议的值。使用JSON中的几个键(包括countryName,airportName,cityName和airportCode)对JSON进行过滤。

有没有一种方法可以对显示结果的优先级进行排序?例如。如果我搜索“ sin”,我想先查看包含该词的机场名称列表之前的城市列表。

我正在使用的当前过滤逻辑:

<input type="text" [value]="formValues.fromAirport" value="" 
on="input-debounced:AMP.setState({location:{sourceItems:airports.airportList.filter(x=> (!event.value 
|| x.cityName.toLowerCase().indexOf((event.value||'').toLowerCase()) > -1 
|| x.airportName.toLowerCase().indexOf((event.value||'').toLowerCase()) > -1 
|| x.countryName.toLowerCase().indexOf((event.value||'').toLowerCase()) > -1 
|| x.airportCode.toLowerCase().indexOf((event.value||'').toLowerCase()) > -1 )) }})">

0 个答案:

没有答案