代码之家  ›  专栏  ›  技术社区  ›  Mai Sirisak

如何在选择选项(如文本)中使用name、ref、defaultValue反应流星

  •  0
  • Mai Sirisak  · 技术社区  · 9 年前

    我与ReactJS创建了一个Meteor项目。

    <FormGroup>
    <ControlLabel>Province</ControlLabel>
        <input
           type="text"
           className="form-control"
           name="province"
           ref={province => (this.province = province)}
           defaultValue={regs && regs.province}
        />
    </FormGroup>
    

    如何在select option、checkbox、radio等中使用name、ref、defaultValue,。。等等。像文本?

    <FormGroup controlId="formControlsSelect"> 
       <ControlLabel>Sex</ControlLabel> 
       <FormControl componentClass="select" name="sex"  ref={sex => (this.sex = sex)} defaultValue={regs && regs.sex}> 
       <option value="male">Male</option> 
       <option value="female">Female</option> 
       </FormControl> 
    </FormGroup>
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Mai Sirisak    9 年前

    我可以通过改变 <FormControl ref=....> to <FormControl inputRef=...>