React-select异步选项未显示

时间:2017-04-12 19:12:25

标签: reactjs react-select

我想在我的react-select列表中显示搜索结果,当用户点击该选项时,它会在下表中完整地加载数据。

这是我的loadIptions

getMovies(e){ 
axios.get(`http://www.omdbapi.com/?t=${e}`)
   .then((response) => {
    return {options: response.data.Title}
})
.catch((error) => {
    console.log(error);
  });
}

我正在将该功能发送到我的搜索中:

    render() {
      return (
         <div className="container">
           <SearchForm onkeydown={this.getMovies}  />
           <MovieList movie={this.state.movie}/>
       </div>
 );
}

但是我不能在输入中显示它,它仍处于加载状态:

<Select.Async
 name="form-field-name"
 value=""
 loadOptions={this.props.onkeydown}
/>

我是如何获得它来展示标题的?

1 个答案:

答案 0 :(得分:1)

你的功能实际上并没有返回任何东西

改变这个:

getMovies(e){ 
axios.get(`http://www.omdbapi.com/?t=${e}`)
   .then((response) => {
    return {options: response.data.Title}
})
.catch((error) => {
    console.log(error);
  });
}

要:

getMovies(e){ 
return axios.get(`http://www.omdbapi.com/?t=${e}`)
   .then((response) => {
    return {options: response.data.Title}
})
.catch((error) => {
    console.log(error);
  });
}