react-dom.development.js:287 uncatch TypeError: 无法读取未定义的属性'value'



我正试图通过将下拉列表中选择的当前值存储在一个名为result的变量中来获取该值。但每次我这样做时,它都会给我带来"未捕获类型错误"。

我已经尝试了一些不同的方法,使用"onClick"onChange">

constructor(props){
super(props);
this.state = {
names: [],
equipments:[],
isLoaded: false,
result: ""
}
handleChange (event) {
this.setState({
result: event.target.value
})
console.log("result=" + this.state.result);
}
render() {
let {names, equipments} = this.state;
let options = names.map(name => {
return {value: name.name, label: name.name};
})
let options3 = equipments.map(equip => {
return {value: equip.value.name, label: equip.value.name};
})
return (
<Select placeholder="Enter Site Name" onChange={event => this.handleChange(event)}
options={options} />
{this.state.result} <hr />
)}
Expected: should return the name of the selected drop down option.
e.g., BNTOR1245#Name1

所以这个问题得到了解决:

handleChange = selectedOption => {
this.setState({ inputValue: selectedOption });
console.log(`Option selected: ${selectedOption.value}`);

相关内容

最新更新