1

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!

4

3 回答 3

0

从https://stackoverflow.com/a/15179532/559079无耻地复制代码

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

function myAjaxFunction (item){
$.ajax({ //DO STUFF HERE });
}
于 2013-09-10T09:24:28.163 回答
0
$('#search-bar').bind("paste", function(e){
    var self = $(this);
    setTimeout(function(){self.trigger("keydown");}, 0);
});
于 2016-10-05T12:19:22.113 回答
-1

(1) 我的懒惰解决方案:调用$('#yourtypeaheadfield').trigger('keyup')“模拟”一个 keyup / keypress 事件 .. 这就是 Typeahead 与 JQuery API 挂钩的方式。

(2)“更好”的答案:明确触发 typeahead 事件$().trigger('typeahead.updater')- 但是我无法弄清楚语法,并且没有记录(至少对于 bootstrap 2.3.2 没有)。

于 2014-10-25T20:09:11.893 回答