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

Javascript 为什么typeahead.js没有显示ajax响应中的所有项目?,javascript,jquery,typeahead.js,bootstrap-typeahead,Javascript,Jquery,Typeahead.js,Bootstrap Typeahead,我试图使用typeahead.js以表单形式显示ajax结果。 起初,我尝试使用默认情况下带有typeahead的Bloodhound建议引擎。但它并没有显示服务器返回的所有项目(我只显示了1个或两个) 下面是我使用的代码 $('.autocomplete').livequery(function () { var input = this; $(input).removeClass('autocomplete'); v

我试图使用
typeahead.js
以表单形式显示ajax结果。 起初,我尝试使用默认情况下带有
typeahead
Bloodhound
建议引擎。但它并没有显示服务器返回的所有项目(我只显示了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);
            });
        })
然后,我尝试在不使用侦探犬的情况下使用以下代码,而不改变结果

 $('.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);
            });
        })
服务器对请求的响应如下:

[
{
    "Text": "Marketing Executive",
    "Value": 1
},
{
    "Text": "CEO",
    "Value": 5
},
{
    "Text": "Manager",
    "Value": 6
},
{
    "Text": "Accountant",
    "Value": 7
}]

这有什么问题?如何让typeahead显示服务器返回的所有结果?

这是控件中的一个错误。这可以通过在
typeahead.bundle.js

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

that._append(query, suggestions.slice(0, that.limit - rendered));
rendered += suggestions.length;

该职位的荣誉

默认情况下,仅显示5条建议,使用
限制
选项增加建议。检查@JSantosh
limit:50
,检查问题。你看不到50个结果吗?@JSantosh我在某个地方读到,当syncresults较少时,typeahead在显示所有异步结果方面存在一些问题。设置更高的限制是在互联网上找到的一种解决办法。