首页 > 解决方案 > 如何将选定的值存储在反应组合框中

问题描述

我创建了一个带有反应的组合框。如何将组合框中选择的值分配给变量,或者我可以存储它?有没有这方面的例子?

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

标签: javascriptnode.jsreactjs

解决方案


您可能会考虑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"/>

推荐阅读