我在使用react-bootstrap-typeahead项目中的AsyncTypeahead时遇到了一个问题,似乎我的onSearch处理程序没有被调用。我可以在页面上看到typeahead,但是当我在其中键入时,handleSearch没有被执行,并且我没有看到任何控制台日志记录。下面是一个简短的示例:
import React, {PropTypes, Component} from 'react';
import AsyncTypeahead from 'react-bootstrap-typeahead';
class CustomTypeahead extends Component {
state = { results: [] }
handleSearch(event) {
console.log("Show me what you got")
// fetch data here and set state to results in a promise
// this.setState(results)
}
render() {
return (
<div>
<AsyncTypeahead
onSearch={this.handleSearch.bind(this)}
options={this.state.results}/>
</div>
)
}
}
任何建议或见解都非常感谢!
发布于 2017-08-04 09:03:34
通过使用以下命令修复:
import { AsyncTypeahead } from 'react-bootstrap-typeahead';而不是
import AsyncTypeahead from 'react-bootstrap-typeahead';并更新到用于react-bootstrap-typeahead的^1.0.0版
https://stackoverflow.com/questions/45496625
复制相似问题