import React from 'react';
import Select from 'react-select';
require("../node_modules/react-select/dist/react-select.css");
const getOptions = (input) => {
return fetch(`/games/uni/autocomplete/${input}`)
.then((response) => {
return response.json();
}).then((json) => {
console.log(json)
return { options: json };
});
}
var SearchBar = React.createClass({
render: function() {
return (
<Select.Async
name="form-field-name"
loadOptions={getOptions} />
)
}
});
export default SearchBar;
console.log(json) 就像:["EA SPORTS FIFA 16", "FIFA 16 Ultimate Team"]
但建议值为空
这里是组件 Async 的 state 和 props
这里是带有示例的官方文档:https ://github.com/JedWatson/react-select#async-options-with-promises
我缺少什么?