Twitter bootstrap 在加载Twitter引导typeahead的源之后执行函数

Twitter bootstrap 在加载Twitter引导typeahead的源之后执行函数,twitter-bootstrap,typeahead,bootstrap-typeahead,Twitter Bootstrap,Typeahead,Bootstrap Typeahead,实际上,我正在使用Twitter引导程序中的插件Typeahead,我想在服务器中的数据加载后添加一个新行 $('.typeahead').typeahead({ source: function (query, process) { return $.get('/typeahead.json', { q: query }, function (data) { return process(data); }); } });

实际上,我正在使用Twitter引导程序中的插件Typeahead,我想在服务器中的数据加载后添加一个新行

$('.typeahead').typeahead({
    source: function (query, process) {
        return $.get('/typeahead.json', { q: query }, function (data) {
            return process(data);
        });
    }
});
一旦数据被加载,我想在下拉列表的末尾添加一个新的查询行


这样做的诀窍是什么?

您必须对以下代码进行一些修改-

// try using id instead of class  
//like id="#MyTypeahead"

var autocomplete = $('#MyTypeahead').typeahead();  
var srcArray = new Array();


// You should assign ur updated source here.  
srcArray = ["Value1","Value2","Value3","Value4","Value5"];  

srcArray.push("New line goes here");
autocomplete.data('typeahead').source = JSON.parse(srcArray);
现在,您的typeahead源代码如下-
[“Value1”、“Value2”、“Value3”、“Value4”、“Value5”、“新行在此显示”]