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