我想从<option>
获取所选<select>
的索引。我尝试使用jQuery,直接获取对象的属性(这表明_this2.selector.current
未定义)和selectedIndex
,但似乎都不起作用。
<div className="cell-content">
<select
id="common-name-selector"
className="form-control"
onChange={() => {
this.handleChange();
presentSpecies = this.selector.target.value;
}}
ref={this.selector}
>
{(this.selector.current = 0)}
<option value="" selected>
Select by Common Name
</option>
{
data.data.species.map((option, index) => {
return (
<option
value={option.index}
key={index}
>
{option.commonName}
</option>
);
})}
</select>
{
//This is the part I'm having trouble with.
setInterval(() => {
console.log(this.selector.current);
// presentSpecies = 0;
presentSpecies = this.selector.current.querySelector;
ReactDOM.render(
<Router />
document.getElementById("root")
);
}, 500);
}
</div>