我想在我的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}
/>
我是如何获得它来展示标题的?
答案 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);
});
}