我尝试了一些东西来显示select
标签的值。
我尝试的第一件事是event.target.value
使用onChange
. 我尝试的第二件事是event.nativeEvent.value
不可能,所以如果你有我的奇迹!我把那个
所以如果你愿意,我会发布我的部分代码:
class App extends Component {
constructor(props) {
super(props);
this._createBounds();
this.state = {
value: 'a'
}
}
_createBounds() {
['_handleSubmit', '_renderTasks', '_handleChange']
.forEach((fn) => this[fn] = this[fn].bind(this));
}
_handleChange(event) {
this.setState({ value: event.currentTarget.value }) // I tried before target.value, or nativeEvent.value
}
render() {
return (
<div className="container">
<div className="list-container">
<div className="list-select">
<select
onChange={this._handleChange()}
className="ant-input selectBox"
style={{width: 200}}
placeholder="Select a person"
ref={ref => {
this._select = ref
}}
value={this.state.value}
defaultValue={this.state.value}
>
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d">D</option>
<option value="e">E</option>
<option value="f">F</option>
<option value="g">G</option>
<option value="h">H</option>
<option value="i">I</option>
<option value="j">J</option>
<option value="k">K</option>
<option value="l">L</option>
<option value="m">M</option>
<option value="n">N</option>
<option value="o">o</option>
<option value="p">P</option>
<option value="q">Q</option>
<option value="r">R</option>
<option value="s">S</option>
<option value="t">T</option>
<option value="u">U</option>
<option value="v">V</option>
<option value="w">W</option>
<option value="x">X</option>
<option value="y">Y</option>
<option value="z">Z</option>
</select>
</div>
</div>
</div>
);
}
}