2017-08-04 106 views
1

我有一个关于react-select组件的问题。奇怪的行为与Select.Async和loadOptions

我有以下代码(coffeescript)和非常奇怪的行为(在gif下面)。问题是 - 我做错了吗?为什么选项在getOptions函数完成后不立即显示?为什么只有在外面点击后才显示?这是超级混乱..我需要你的帮助家伙!

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

这个属性添加到Select.Async:filterOption = {()=>(真)} 更具体地写:

<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} 
/> 

希望这将解决您的问题