0
我已经用ReactJS创建了Meteor项目。 对于创建/编辑页面,我用的是同一个页面,在文字输入,我有以下代码:如何在文本等选择选项中使用name,ref,defaultValue? - 在React流星
<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>
'name'和'ref'工作与他们相同的解决这个问题,'defaultValue'工作的''元素上,而对于复选框/收音机你'defaultChecked'。 – pawel
嗨帕维尔,非常感谢。 defaultValue运作良好,但我发现其他错误,“场性未定义”。请参阅我在该主题上编辑的代码。 –
如果' '是一个react-bootstrap控件,我想你应该使用'inputRef'而不是'ref' https://react-bootstrap.github.io/components.html#forms-props-form-control –
pawel