我正在使用 React-Select Plus 控件来绑定 React 中的下拉菜单。我在 React 中绑定异步选项组下拉时发现问题。这是我的代码:
getSearch = (input) => {
if (!input) {
return Promise.resolve({ options: [] });
}
const newstate = this.state;
this.setState({ newstate });
newstate.loadingtext = 'Searching...';
const searchLocation = Object.assign({}, cookie.load('cLocation'));
searchLocation.searchText = input;
searchLocation.isBusiness = true;
const myInit = {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify(searchLocation),
};
return fetch(`url/methodname`, myInit)
.then(response => response.json())
.then(json => [{ value: json.data, label: json.data }]);
}
gotoSearch = (value) => {
window.open(value.html_url);
}
<Select.Async
onChange={this.onChange}
onValueClick={this.gotoSearch}
valueKey="placeID"
labelKey="cityState"
loadOptions={this.getSearch}
value={this.state.value}
loadingPlaceholder={this.state.loadingtext}
noResultsText="No results found"
placeholder="Name, City, Zip"
options={ops}
/>
我参考这个网址:http: //github.hubspot.com/react-select-plus/
请帮我。