當我選擇一個國家輸入未更新顯示它。我可以通過控制檯記錄該值,以便我知道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)}
/>
下拉擁有可用的選項和我可以選擇它們,控制檯日誌將記錄我選擇的值。我有另一個控制檯日誌記錄狀態,並記錄正確的狀態。我只是不知道爲什麼輸入不顯示我選擇的選項。
Wher是你的輸入字段?另外onSelectCountry,在setState中,它應該是val,而不是val.Value –