Javascript minlength和items在引导和如何添加滚动条以获取建议的typeahead中不起作用。

Javascript minlength和items在引导和如何添加滚动条以获取建议的typeahead中不起作用。,javascript,twitter-bootstrap-3,typeahead,Javascript,Twitter Bootstrap 3,Typeahead,我在typeahead中添加了items和minlength,但它不起作用,只有默认设置起作用,下面是参考代码。解决方案是什么?如果建议超过5条,如何添加滚动条。请帮忙 $.ajax({ type: "GET", url: "https://jsonplaceholder.typicode.com/comments", dataType: "text", success: function(data) { p

我在typeahead中添加了items和minlength,但它不起作用,只有默认设置起作用,下面是参考代码。解决方案是什么?如果建议超过5条,如何添加滚动条。请帮忙

$.ajax({
        type: "GET",
        url: "https://jsonplaceholder.typicode.com/comments",
        dataType: "text",
        success: function(data) {
            processData(data);
         }   

     });

    function processData(data) {
         var myData = JSON.parse(data);
         var Names = [];
         for (var i = 0; i<myData.length; i++) {
            Names.push(myData[i].name);
         }

        $("#typeahead").typeahead({
            source: Names});

        $("#typeahead").typeahead({
            items : 5,
            minLength : 3
        });

        $("#typeahead").typeahead({
            matcher: function (item) {
                if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
                return true;
               }
            }
        });

        $("#typeahead").typeahead({
            sorter: function(items){
                return items.sort(); 

            }
        });  

        $("#typeahead").typeahead({  
                updater: function(item){
                selectedName = myData[item].name;
                return item;
           }
        });
        $("#typeahead").typeahead({  
            highlighter: function(item){
                var regex = new RegExp( '(' + this.query + ')', 'gi' );
                return item.replace( regex, "<strong>$1</strong>" );
            }
        });
    } 
$.ajax({
键入:“获取”,
url:“https://jsonplaceholder.typicode.com/comments",
数据类型:“文本”,
成功:功能(数据){
过程数据(数据);
}   
});
函数processData(数据){
var myData=JSON.parse(数据);
变量名称=[];

对于(var i=0;i您多次启动了同一个typeahead,我想只有最后设置的选项会影响该元素。我将代码更改为将所有内容合并为一个
.typeahead()

$.ajax({
    type: "GET",
    url: "https://jsonplaceholder.typicode.com/comments",
    dataType: "text",
    success: function(data) {
        processData(data);
        console.log('Hi there'); // Check if this is printed in console to verify the request ended with success
     }   

 });

    function processData(data) {
         var myData = JSON.parse(data);
         var Names = [];
         for (var i = 0; i<myData.length; i++) {
            Names.push(myData[i].name);
         }

        $("#typeahead").typeahead({
            source: Names,
            items : 5, // This will always limit the results to 5, scrolling will not load more items.
            minLength : 3,
            matcher: function (item) {
                if(item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
                   return true;
               }
            },
            sorter: function(items) {
                return items.sort(); 
            },  
            updater: function(item){
                selectedName = myData[item].name;
                return item;
           }, 
           highlighter: function(item) {
                var regex = new RegExp( '(' + this.query + ')', 'gi' );
                return item.replace( regex, "<strong>$1</strong>" );
           }
        });
    } 
.tt-menu {
    max-height: 300px; // set any hight
    overflow-y: auto; // auto or scroll, with scroll a scrollbar will be visible even if the max-height was not reached
}