我尝试检索所选选项和optgroup上的值,但我不知道答案。我尝试使用e.target.value,parentELement ...我迷路了!
这是代码:
state = {
selectValue : "default"
}
handleSelectChange = (e) => {
var target = e.target
var parent = target.parentElement
console.log("parent:", parent);
// this.setState({
// selectValue: e.target.option
// })
}
render(){
const { open, toggle, title, commande, label, updateOrderStatus } = this.props
console.log(this.state.selectValue)
return(
<Modal isOpen={open} toggle={toggle}>
<ModalHeader toggle={toggle}>{title}</ModalHeader>
<ModalBody>
<FormGroup />
<Label>Selectionnez un statut</Label>
<Input type="select" name="select" onChange={this.handleSelectChange}>
{_.keys(commande.pack.specificationSteps).map((key, index) => {
return (
<optgroup label={key} key={index}>
{Object.keys(commande.pack.specificationSteps[key]).map((value, index) => {
return <option key={index}>{value}</option>
})}
</optgroup>
)
})}
</Input>
</ModalBody>
<ModalFooter>
<RoundButton label={label} onClick={() => updateOrderStatus(commande.id)} />
</ModalFooter>
</Modal>
)
}
}
非常感谢您的帮助