指定默认值的反应,引导

问题描述:

[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'的东西,则输入字段中显示的值将是'默认值'。 –

我没有测试,但是从阵营引导source code for FormControl好像使用defaultValue道具应该工作:

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