【问题标题】:React Select Async反应选择异步
【发布时间】:2021-02-06 16:34:04
【问题描述】:

我正在尝试使用 React Select Async (https://react-select.com/home#async) 有条件地传递选项,但没有成功。比如:

AsyncSelect

关注 CodeSandbox 链接: CodeSandbox

请帮帮我?

非常感谢您

【问题讨论】:

  • 这个条件有什么作用?为什么在 loadoptions 中定义它?

标签: reactjs asynchronous react-select


【解决方案1】:

根据文档here,您需要有 'defaultOptions' 和 'loadOptions' 期待承诺。

  1. 添加defaultOptionsloadOptions={loadOptions}

    <AsyncSelect
       cacheOptions
       loadOptions={loadOptions}
       defaultOptions
       onInputChange={this.handleInputChange}
     />
    
  2. loadOptions函数中添加条件

    const loadOptions = (inputValue, callback) => {
      setTimeout(() => {
        if (conditionally === 0) {
          callback(filterColors(inputValue));
        } else return {};
      }, 1000);
    };
    

Codesandbox

【讨论】:

    猜你喜欢
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多