阿尔戈利亚重定向到搜索结果
Algolia redirect to search results
我在将搜索结果重定向到要显示结果的页面时遇到问题。希望在标题中包含搜索栏,以便我的结果显示在结果页面或类似内容上。一切都是通过教程(Laracasts)完成的,仍在学习javascript,所以我有点卡在这里。一些帮助会很棒!
索引刀片.php
<script src="http://code.jquery.com/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js"></script>
<script src="http://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.1/vue.js"></script>
<script>
new Vue({
el: 'body',
data: {
query: '',
users: []
},
ready: function () {
this.client = algoliasearch('', '');
this.index = this.client.initIndex('test_drive_contacts');
$('#typeahead').typeahead(null, {
source: this.index.ttAdapter(),
displayKey: 'firstname',
templates: {
suggestion: function (hit) {
return '<div>' +
'<h4 class="high">' + hit._highlightResult.firstname.value + '</h4>' +
'<h5 class="high">' + hit._highlightResult.company.value + '</h5>'
+ '</div>';
}
}
})
.on('typeahead:select', function (e, suggestion) {
this.query = suggestion.firstname;
}.bind(this));
},
methods: {
search: function () {
this.index.search(this.query, function (error, results) {
this.users = results.hits;
}.bind(this));
}
}
});
</script>
这是搜索输入:
<input id="typeahead" type="text" class="form-control" v-model="query"
v-on="keyup: search | key 'enter'">
<article v-repeat="user: users">
<h2>@{{ user.firstname }}</h2>
<h4>@{{ user.company }}</h4
</article>
在 JavaScript 中将用户重定向到页面就像执行一样简单
window.location = 'your_url_here'
如果您只是想在用户键入 Enter 时重定向到/search?q=query
页面,这就像将您使用的输入包装在表单中一样简单。
<form action="/search" method="GET">
<input type="search" id="your-input" name="q" />
</form>
如果要重定向到项目页面,typeahead:select
事件会为您提供所选选项:
$('#your-input')
.typeahead(/* ... */)
.on('typeahead:select', function (e, suggestion) {
window.location = suggestion.url;
});
相关文章:
- jQuery使用inArray搜索和重定向邮政编码
- 谷歌CSE-我可以显示嵌入在我的网站上的页面本身,而不是从结果视图重定向到页面
- 如果当前网址不包含位置搜索,请重定向到主页
- 如何在重定向到另一个页面后维护一个页面值(搜索值和表记录值)
- 节点 js 护照重定向结果为 404
- 当将页面提交到谷歌表单时,它将打印结果,然后使用 javascript 重定向到主页
- 使用 JavaScript 搜索字符串,如果结果为 true,则重定向页面
- 阿尔戈利亚重定向到搜索结果
- 如何将自动完成搜索框重定向到显示视图
- 如何先从Firebase获取结果,然后重定向到另一个页面
- Javascript在正文文本中搜索关键字,如果找到,则重定向到特定的URL
- 重定向页面覆盖谷歌搜索中的真实页面
- 在页面加载过程中,在不重定向到其他页面的情况下,在同一页面上打印距离结果
- 如何在ajax搜索中重置值以分页结果
- 加载结果后重定向到新页面
- 我应该使用哪些功能来url安全搜索重定向
- 如何从谷歌网页搜索api重定向搜索结果
- 对单个搜索结果进行重定向
- 基于脚本结果重定向页面
- ASP.NET MVC jQuery JSON 结果重定向 URL