为什么 typeahead.js 没有显示 ajax 响应中的所有项目?

Lib*_* TK 2 javascript jquery bootstrap-typeahead typeahead.js

我正在尝试typeahead.js用于在表单中显示 ajax 结果。起初我尝试使用默认Bloodhound附带的建议引擎typeahead。但它没有显示服务器返回的所有项目(我只显示 1 个或有时两个)。

以下是我使用的代码;

 $('.autocomplete').livequery(function () {
            var input = this;
            $(input).removeClass('autocomplete');

            var _source = new Bloodhound({
                limit: 25,
                datumTokenizer: Bloodhound.tokenizers.obj.whitespace('Value'),
                queryTokenizer: Bloodhound.tokenizers.obj.whitespace('Text'),
                prefetch: $(input).attr('data-source'),
                remote: {
                    url: $(input).attr('data-source') + '?query=%QUERY',
                    wildcard: '%QUERY'
                }
            });

            _source.initialize();

            $(input).typeahead({
                hint: true,
                highlight: true,
                minLength: 0
            }, {
                displayKey: 'Text',
                source: _source,
                templates: {
                    notFound: 'No results found'
                }
            });

            $(input).on('typeahead:selected', function (evt, item) {
                $(input).parent().parent().find('input[type="hidden"]').val(item.Value);
            });
        })
Run Code Online (Sandbox Code Playgroud)

然后我尝试在没有 Bloodhound 的情况下使用以下代码进行操作,结果没有任何变化;

 $('.autocomplete').livequery(function () {
            var input = this;
            $(input).removeClass('autocomplete');

            $(input).typeahead({
                hint: true,
                highlight: true,
                limit: 50,
                minLength: 0
            }, {
                displayKey: 'Text',
                source: function (query, syncResults, asyncResults) {
                    $.get($(input).attr('data-source') + '?query=' + query, function (data) {
                        asyncResults(data);
                    });
                },
                templates: {
                    notFound: 'No results found'
                }
            });

            $(input).on('typeahead:selected', function (evt, item) {
                $(input).parent().parent().find('input[type="hidden"]').val(item.Value);
            });
        })
Run Code Online (Sandbox Code Playgroud)

服务器对请求的响应如下;

[
{
    "Text": "Marketing Executive",
    "Value": 1
},
{
    "Text": "CEO",
    "Value": 5
},
{
    "Text": "Manager",
    "Value": 6
},
{
    "Text": "Accountant",
    "Value": 7
}]
Run Code Online (Sandbox Code Playgroud)

这有什么问题?以及如何提前输入以显示服务器返回的所有结果?

Kir*_*n B 7

这是控件中的错误。这可以通过以下代码更改来解决typeahead.bundle.js

切换线路 1723 和 1724 使其看起来像这样

that._append(query, suggestions.slice(0, that.limit - rendered));
rendered += suggestions.length;
Run Code Online (Sandbox Code Playgroud)

Bootstrap Typeahead帖子的荣誉没有按预期显示提示