Reactjs 当React已在change select2中呈现时,无法刷新更新
在select2下拉列表中选择时出错我正在使用react-select2作为国家/地区和城市下拉列表: 代码如下:Reactjs 当React已在change select2中呈现时,无法刷新更新,reactjs,jquery-select2,react-select,Reactjs,Jquery Select2,React Select,在select2下拉列表中选择时出错我正在使用react-select2作为国家/地区和城市下拉列表: 代码如下: <Select2 name="country" ref={this.state.country} value={this.state.country} data={ this.props.countries ? this.props.countries.map(e => { ret
<Select2
name="country"
ref={this.state.country}
value={this.state.country}
data={
this.props.countries ? this.props.countries.map(e => {
return {
id: e.Id,
text: e.Name,
};
})
:
[]
}
options={
{
dropdownParent: '.dropdown-country-field'
}
}
onChange={(e) => {
this.setState({
country: e.target.value
})
this.props.getAllCities(this.state.country);
}}
/>
{
返回{
id:e.id,
文本:e.名称,
};
})
:
[]
}
选择权={
{
dropdownParent:“.dropdown国家/地区字段”
}
}
onChange={(e)=>{
这是我的国家({
国家:e.target.value
})
this.props.getAllCities(this.state.country);
}}
/>
setState中的这个e.target.value不起作用,相反,您需要先获取该值,(e)=>{const{value}=e.target;This.setState({country:value})仍然会收到相同的警告错误