简体   繁体   English

粘贴事件时提前触发Bootstrap类型

[英]Trigger Bootstrap typeahead on paste event

I've been trying to manually trigger the typeahead search on right-click paste by catching the paste event as follows but I can't seem to find a way to trigger the typeahead's 'matcher' function manually to query the entered string. 我一直在尝试通过捕获粘贴事件来手动触发右键单击粘贴上的预输入搜索,如下所示,但我似乎找不到找到一种方法来手动触发预输入的“匹配器”功能来查询输入的字符串。

$('#search-bar').bind("paste", function(e)
{
    $(this).trigger("keydown"); // Tried keyup, input to no avail!
});

Any help would be much appreciated! 任何帮助将非常感激!

Shamelessly copied code from https://stackoverflow.com/a/15179532/559079 来自https://stackoverflow.com/a/15179532/559079的无耻复制的代码

        $('#search-bar').typeahead({
            'updater' : function(item) {
              myAjaxFunction(item);
            }
        });

function myAjaxFunction (item){
$.ajax({ //DO STUFF HERE });
}
$('#search-bar').bind("paste", function(e){
    var self = $(this);
    setTimeout(function(){self.trigger("keydown");}, 0);
});

(1) my lazy solution: call $('#yourtypeaheadfield').trigger('keyup') to "impersonate" a keyup / keypress event .. this is how Typeahead hooks into the JQuery API. (1)我的惰性解决方案:调用$('#yourtypeaheadfield').trigger('keyup')以“模拟”一个keyup / keypress事件..这就是Typeahead钩接到JQuery API的方式。

(2) "better" answer: fire the typeahead event exlicitly - $().trigger('typeahead.updater') - I could not figure out the syntax, though, and it is not documented (at least not for bootstrap 2.3.2). (2)“更好”的答案:明确$().trigger('typeahead.updater') typeahead事件- $().trigger('typeahead.updater') -但是,我无法弄清楚该语法,并且该语法没有记录在案(至少对于bootstrap 2.3而言)。 2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM