【发布时间】:2020-08-11 18:11:06
【问题描述】:
我正在尝试使用以下代码清除函数中的输入。
import {Typeahead} from 'react-bootstrap-typeahead';
type requestState={
value:string[]
}
class Data extends Component<{},requestState> {
constructor(props){
super(props);
this.state = {
value: [],
}
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.typeahead.getInstance().clear();
}
render() {
return(
<Typeahead
ref={(ref) => this.typeahead = ref}
id="data"
labelKey="data"
multiple={true}
options={this.state.values}
placeholder="Choose a data.."
onChange={(e) => this.handleChange(e)}
/>
);
}
}
export default Data;
当我尝试使用此代码一次清除输入时,我收到以下错误:“类型 'Data' 上不存在属性 'typeahead'”。
有人可以帮助我如何定义 typeahead 属性以及必须做哪些更改才能使其正常工作。
【问题讨论】:
标签: reactjs bootstrap-typeahead react-bootstrap-typeahead