2016-12-15 87 views
3

[email protected]我使用FormControl Input屬性defaultValue到指定Input被廢棄在組合框中指定默認值的反應,引導

<Input type='select' 
      ref='templateSelect' 
      defaultValue={this.state.templateId} 
      onChange={this.handleTemplateChange}> 
    {options} 
</Input> 

應如何在[email protected]處理選擇起始值(最新的)並且這裏應該使用的新組件FormControl不提供這樣的屬性?

應該用value代替嗎?

<FormControl type='select' 
      ref='templateSelect' 
      value={this.state.templateId} 
      onChange={this.handleTemplateChange}> 
    {options} 
</FormControl> 

或者,也許是這樣的:

value={this.state.templateId || 'default value'} 
+0

據正如我所看到的,「FormControl」的值屬性幾乎與常規的「input」值屬性相對應,所以使用值來設置默認值,如上所述,應該可以正常工作。我不會推薦'value = {this.state.templateId || 'default value'}',因爲如果您的更改處理程序將'this.state.templateId'設置爲解析爲'false'的東西,則輸入字段中顯示的值將是'默認值'。 –

回答

7

我沒有測試,但是從陣營引導source code for FormControl好像使用defaultValue道具應該工作:

<FormControl type="select" 
    ref="templateSelect" 
    defaultValue={this.state.templateId} 
    onChange={this.handleTemplateChange}> 
    {options} 
</FormControl>