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

问题描述 投票:0回答:1

我正在尝试通过将下拉列表中选择的当前值存储在名为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
reactjs react-select
1个回答
0
投票

所以这个问题解决了:

handleChange = selectedOption => {
    this.setState({ inputValue: selectedOption });
    console.log(`Option selected: ${selectedOption.value}`);
© www.soinside.com 2019 - 2024. All rights reserved.