【发布时间】:2017-08-03 04:02:11
【问题描述】:
当我选择一个国家时,输入不会更新以显示它。我可以控制台记录该值,因此我知道 onChange 正在更新它。
this.state = {
countrySelection: "",
countryListFormatted: [
{Value: "France", label: "France"},
{Value: "Germany", label: "Germany"},
{Value: "Greece", label: "Greece"},
{Value: "Turkey", label: "Turkey"},
{Value: "Italy", label: "Italy"},
{Value: "Netherlands", label: "Netherlands"},
{Value: "Portugal", label: "Portugal"},
{Value: "Spain", label: "Spain"},
{Value: "Switzerland", label: "Switzerland"},
{Value: "United Kingdom", label: "United Kingdom"},
{Value: "United States of America", label: "United States of America"}
}
我没有显示整个页面,但下面是我的 onChange 处理程序:
onSelectCountry(val){
this.setState({countrySelection: val.Value})
console.log(val)
}
以及动作选择组件:
<Select
searchable={true}
style={{border: "none", boxShadow: "none", highlight: "none"}}
placeholder="Country"
name="country-selection"
value={this.state.countrySelection}
options={this.state.countryListFormatted}
onChange={this.onSelectCountry.bind(this)}
/>
下拉列表中有可用的选项,我可以选择它们,控制台日志将记录我选择的值。我有另一个控制台日志记录状态,那就是记录正确的状态。我只是不知道为什么输入没有显示我选择的选项。
【问题讨论】:
-
你的输入框在哪里?还有onSelectCountry,在setState中,应该是val,而不是val.Value
标签: react-select