antd select如何支持既能输入不存在的选项又能进行下拉框选择

1.Select必须具备onSearch,onBlur,onChange这三个属性;
showSearch
value={this.state.value}
onSearch={…}
onBlur={…}
onChange={…}

{optionsFor}
2.在onSearch中使用回调,并设置state {this.setState({ 'newState':val })}} onBlur={} onChange={...} > {optionsFor} 3.onChange设置回调 {this.setState({ 'newState':val })}} onBlur={} onChange={this.handleChange} > {optionsFor} 3.onBlur中利用三目判断,并返回输入的值 {this.setState({ 'newState':val })}} onBlur={()=>{ return this.state.newState?this.handleChange:null }} onChange={this.handleChange} > {optionsFor} 4.最后一步,也是最重要的,必须利用delete命令移除在state中设置的newState; let finalState = this.state; delete newState['newState]; this.setState({finalState})

你可能感兴趣的:(react)