Typeahead Bloodhound 在预取发生时执行某些操作
Bloodhound 的预取功能对我来说非常有用,但我想在预取发生时禁用我的输入。
有谁知道一种方法来检测预取何时发生,执行某些操作,然后在预取完成时执行其他操作?这是我的代码。
// Nav typeahead
var costCenters = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('bloodhound'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: dsg_site_root + 'autocomplete/costCenterPullDownNamesComplete'
})
var employees = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('bloodhound'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: dsg_site_root + 'autocomplete/employeePullDownNamesComplete'
})
$(function() {
$('#navSearch').typeahead({
highlight: true,
maxItem: 20,
},
{
name: 'costCenters',
display: 'display',
source: costCenters,
templates: {
header: '<h6 class="ml-3 mt-2 text-secondary">Cost Centers</h6>'
}
},
{
name: 'employees',
display: 'display',
source: employees,
templates: {
header: '<h6 class="ml-3 mt-2 text-secondary">Employees</h6>'
}
})
$('#navSearch').bind('typeahead:select', function(ev, chosen) {
if(chosen.category == 'employees') {
window.location.href = dsg_site_root + 'employee/index/' + chosen.id
} else {
window.location.href = dsg_site_root + 'costCenter/index/' + chosen.id
}
})
})
提前致谢。
Bloodhound's prefetch feature is working great for me, but I would like to disable my inputs while the prefetch is happening.
Does anyone know of a way to detect when the prefetch is happening, do something, and then do something else when the prefetch is complete? Here is my code.
// Nav typeahead
var costCenters = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('bloodhound'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: dsg_site_root + 'autocomplete/costCenterPullDownNamesComplete'
})
var employees = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('bloodhound'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: dsg_site_root + 'autocomplete/employeePullDownNamesComplete'
})
$(function() {
$('#navSearch').typeahead({
highlight: true,
maxItem: 20,
},
{
name: 'costCenters',
display: 'display',
source: costCenters,
templates: {
header: '<h6 class="ml-3 mt-2 text-secondary">Cost Centers</h6>'
}
},
{
name: 'employees',
display: 'display',
source: employees,
templates: {
header: '<h6 class="ml-3 mt-2 text-secondary">Employees</h6>'
}
})
$('#navSearch').bind('typeahead:select', function(ev, chosen) {
if(chosen.category == 'employees') {
window.location.href = dsg_site_root + 'employee/index/' + chosen.id
} else {
window.location.href = dsg_site_root + 'costCenter/index/' + chosen.id
}
})
})
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论