【问题标题】:Twitter TypeAhead show all results programmaticallyTwitter TypeAhead 以编程方式显示所有结果
【发布时间】:2014-06-03 08:15:31
【问题描述】:

我已经为此烦恼了一段时间。 SO和其他网站周围还有其他答案说,如果我将input的值更改为其他值,然后恢复为我的原始值,TypeAhead将显示。

在我的情况下没有任何效果。

我这样检索我的结果:

$(element).typeahead({
    hint      : true,
    highlight : true, // This is to bold words that match the query
    minLength : queryLength
}, {
    name      : "results",
    displayKey: "value",
    source    : bhResults.ttAdapter()
});

之后,我尝试强制显示一个包含所有结果的下拉列表,如下所示:

    window.setTimeout(function () {
        $(element).typeahead('val', value);
        $(element).focus();
        $(element).trigger("input");
        $(element).val('mood');
    }, 1000);

但是,没有任何效果!

【问题讨论】:

    标签: jquery twitter-typeahead


    【解决方案1】:

    其中一个 github 问题涉及一种解决方法:https://github.com/twitter/typeahead.js/issues/798

    【讨论】:

    • 嗨,我认为这对我也有用,因为 jsfiddle 工作正常,但我使用的是猎犬建议引擎,并且向下箭头没有使列表出现......你有没有主意?这是我认为可以工作的小提琴:jsfiddle.net/5xxYq/30 当您键入字母但不能使用向下箭头或单击时,它可以正常工作。谢谢!
    【解决方案2】:

    这对我有用:

    ( function( $ )
    {
        function obtainer(query, cb) 
        {
            var filteredList = $.grep( allowed_sites, function (item, index) {
                return item.value.match(query);
            });
    
            var mapped = $.map( filteredList, function (item) { return item }); // data is already formatted as array of objects with with id/value keys, so return whole "row" object
            cb( mapped );
        }
    
        $('#my-container .typeahead').typeahead(
            {
                hint: true,
                highlight: true,
                minLength: 0
            },
            {
                name: 'my-typeahead',
                displayKey: 'value',
                source: obtainer 
            }
        ).on( 'typeahead:autocompleted typeahead:selected keyup', function(e, row) 
            {
                // do stuff with data
            } 
        ).on( 'typeahead:opened', function() 
            {
                var ev = $.Event("keydown");
                ev.keyCode = ev.which = 40;
                $(this).trigger(ev);
                return true
            } 
        );
    } )( jQuery );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-28
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      • 2019-11-11
      相关资源
      最近更新 更多