我正在使用 react-select-plus当我通过键盘在它们之间导航时,我试图获取突出显示项的值,
我怎样才能让它工作?
这是我的代码示例:
class App extends Component {
constructor() {
super();
}
loadOptions(input, callback) {
setTimeout(() => {
callback(null, {
options: [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' }
],
complete: true
});
}, 500);
};
render() {
return (
<div>
<Async
loadOptions={this.loadOptions}
/>
</div>
);
}
}
希望你能帮我解决这个问题
最佳答案
我终于找到了如何获取当前突出显示的项目:
class App extends Component {
constructor() {
super();
}
keyUp() {
let item = ReactDOM.findDOMNode(document.getElementsByClassName('Select-option is-focused')[0]);
console.log(item.textContent);
}
loadOptions(input, callback) {
setTimeout(() => {
callback(null, {
options: [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' }
],
complete: true
});
}, 500);
};
render() {
return (
<div tabIndex="0" onKeyUp={this.keyUp.bind(this)}>
<Async
loadOptions={this.loadOptions}
/>
</div>
);
}
}
关于javascript - 如何用react-select-plus获取高亮项的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52002123/