javascript - 如何将选定的值存储在反应组合框中
问题描述
我创建了一个带有反应的组合框。如何将组合框中选择的值分配给变量,或者我可以存储它?有没有这方面的例子?
const PPP1 = props => {
return (
<div className='padding-div'>
<FormGroup controlId="exampleForm.SelectCustom" className='col-8'>
<FormLabel>1- Select Sector</FormLabel>
<FormControl as="select" custom>
<option> </option>
<option>Agriculture</option>
<option>Mining</option>
<option>Information</option>
<option>Finance</option>
<option>Real Estate</option>
<option>Other</option>
</FormControl>
</FormGroup>
</div>
)
}
export default PPP1
解决方案
您可能会考虑onChange
在 FormControl 组件上添加道具。即在这个
const handleChange = (event) => {
setState({ ...state, [event.target.name]: event.target.checked });}
<FormControlLabel
control={<Checkbox checked={gilad} onChange={handleChange} name="gilad" />}
label="Gilad Gray"/>
推荐阅读
- java - ObjectBox Java 有时会抛出错误 java.lang.ClassNotFoundException: kotlin.text.Charsets
- c# - 在获取/设置的所有日期时间执行转换?
- google-cloud-platform - v2 和 v3 通用模型每天的字符数限制问题
- kubernetes - 动态持久卷调整大小
- flutter - Flutter_Swiper Carousel 将分页指示器显示为条形
- google-workflows - 如何在工作流中获取执行 ID
- azure - Azure Purview 支持 ADF 数据流中的 Delta 格式接收器
- python - 如何让 Python 使闰年函数类似于范围(开始、停止、步进)?
- elasticsearch - 弹性搜索 NEST (.net) SQL
- spyder - 在 Spyder IDE 中获取 github 的暗模式