Select.Async和loadOptions的奇怪行为

时间:2017-08-04 11:15:30

标签: react-select

我对react-select组件有疑问。

我有以下代码(coffeescript)和非常奇怪的行为(在下面的gif上)。问题是 - 我做错了吗?为什么在getOptions func完成后没有立即显示选项?为什么他们只在外面点击后显示?这太令人困惑了......我需要你的帮助!

getOptions = (value) =>
  return Promise.resolve({options: []}) unless value
  api.geocoder(value).then (data) =>
    countries = [
      {value: 'A', label: 'A'}
      {value: 'B', label: 'B'}
    ]
    console.info(countries)
    {options: countries}

<Select.Async
  className="ads-filter__select"
  value={@props.country_code}
  onChange={(option) => @props.onChange('country_code', option)}
  clearable={false}
  placeholder={I18n.t('ads.country')}
  loadOptions={getOptions}
/>

1 个答案:

答案 0 :(得分:1)

Add this property to Select.Async: filterOption={() => (true)} To be more specific write:

<Select.Async
  className="ads-filter__select"
  value={@props.country_code}
  filterOption={() => (true)}
  onChange={(option) => @props.onChange('country_code', option)}
  clearable={false}
  placeholder={I18n.t('ads.country')}
  loadOptions={getOptions}
/>

Hope this will solve your issue