React selecting option with object as attribute value

前端 未结 4 846
时光说笑
时光说笑 2020-12-11 00:29

I have an issue with react when I want to change the selected option. The problem is that the value is an object and I can\'t pass it in option value attribut.

See t

4条回答
  •  死守一世寂寞
    2020-12-11 01:01

    Convert the object to JSON string, and pass it as value.

    And convert the string back to object in the handler.

    handleChange(event) {
        let obj = JSON.parse(event.target.value); //object
      }
    
      render() {
        
      }
    

提交回复
热议问题