我正在尝试在库SearchBox的Searchkit组件上跟踪onChange事件。我想在输入字段下面制作某种自动完成弹出窗口。
我有一个Searchbar组件和一个SearchbarPopup组件。当我在Searchbox输入中输入内容时,我希望在输入为空时显示或隐藏。但是现在我可以从console.log获得响应。
export class Searchbar extends Component {
constructor(props){
super(props)
this.onChange = this.onChange.bind(this)
}
onChange(){
console.log('input has changed!')
}
render() {
return (
<SearchkitProvider searchkit={searchkit}>
<Layout>
<div className="search">
<div className="search_query">
<SearchBox
autofocus={true}
searchOnChange={true}
onChange={this.onChange}
prefixQueryFields={[
"Author",
"Title"
]}
/>
</div>
</div>
</Layout>
</SearchkitProvider>
);
}
}
呈现HTML
<div id="cb_Zoekbalk">
<div class="sk-layout">
<div class="search">
<div class="search_query">
<div class="sk-search-box">
<form>
<div class="sk-search-box__icon"></div>
<input type="text" data-qa="query" class="sk-search-box__text" placeholder="Waar ben je naar op zoek?" value="">
<input type="submit" value="search" class="sk-search-box__action" data-qa="submit">
<div data-qa="loader" class="sk-search-box__loader sk-spinning-loader is-hidden"></div>
</form>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
在我的项目中,我还需要在SearchBox查询更改时设置一个监听器。以下是我在哪里可以找到回复的地方:
searchkit.setQueryProcessor((plainQueryObject) => {
console.log('input has changed!')
return plainQueryObject
})