指定默认值的反应,引导
问题描述:
在[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'}
答
我没有测试,但是从阵营引导source code for FormControl好像使用defaultValue
道具应该工作:
<FormControl type="select"
ref="templateSelect"
defaultValue={this.state.templateId}
onChange={this.handleTemplateChange}>
{options}
</FormControl>
据正如我所看到的,“FormControl”的值属性几乎与常规的“input”值属性相对应,所以使用值来设置默认值,如上所述,应该可以正常工作。我不会推荐'value = {this.state.templateId || 'default value'}',因为如果您的更改处理程序将'this.state.templateId'设置为解析为'false'的东西,则输入字段中显示的值将是'默认值'。 –