【发布时间】:2018-08-22 00:50:13
【问题描述】:
我关注了他们的tutorial,但它总是显示搜索结果页面,即使页面首次加载并且搜索框的内容为空。我尝试添加queryHook 并且仅在术语不为空时进行搜索,但在加载页面时仍会显示搜索结果。事实上,queryHook 甚至不会在首次加载时被调用。只有在您在搜索框中键入时才会调用它。您如何隐藏搜索结果除非用户开始输入?
https://community.algolia.com/instantsearch.js/v2/widgets/searchBox.html#usage
这可行,但我认为这不是正确的方法,因为它仍然在空文本框上进行搜索。此外,当您通过单击右侧的X 重置搜索词时,它不会隐藏结果(因为它不会调用queryHook)。
<main id="results" class="collapse">
<div id="hits"></div>
<div id="pagination"></div>
</main>
# CoffeeScript
search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-input',
queryHook: (term, searchFunction) ->
console.log "term = #{term}"
if term
$('#results').show()
else
$('#results').hide()
searchFunction(term)
【问题讨论】:
标签: algolia