Reactjs 反应选择异步选项不显示
我想在我的Reactjs 反应选择异步选项不显示,reactjs,react-select,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); });
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>
);
}
render(){
返回(
);
}
但是,我无法将其显示在输入中,它处于加载状态:
<Select.Async
name="form-field-name"
value=""
loadOptions={this.props.onkeydown}
/>
你知道我如何让它显示标题吗?你的函数实际上没有返回任何内容 更改此项:
getMovies(e){
axios.get(`http://www.omdbapi.com/?t=${e}`)
.then((response) => {
return {options: response.data.Title}
})
.catch((error) => {
console.log(error);
});
}
致:
您确定response.data.Title是实际的值数组吗?您还检查了您的承诺是否得到了返回我已经尝试返回:
return[{value:response.data.imdbID,label:response.data.Title}]代码>请在下面检查。您的函数实际上并没有返回任何内容,只是进行了api调用。还要确保response.data.Title是一个实际的值数组
getMovies(e){
return axios.get(`http://www.omdbapi.com/?t=${e}`)
.then((response) => {
return {options: response.data.Title}
})
.catch((error) => {
console.log(error);
});
}