Typeahead Bloodhound 在预取发生时执行某些操作

发布于 2025-01-11 10:19:56 字数 1573 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文