1

I'm actually using the plugin Typeahead from Twitter bootstrap and I would like to add a new row after the data from my server are loaded.

$('.typeahead').typeahead({
    source: function (query, process) {
        return $.get('/typeahead.json', { q: query }, function (data) {
            return process(data);
        });
    }
});

Once the data are loaded I would like to add a new row with the query at the end of the dropdown.

What is the trick to do that?

4

1 回答 1

0

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

// 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);

现在您的预输入源看起来像这样-
["Value1","Value2","Value3","Value4","Value5","New line goes here"]

于 2014-01-29T07:06:19.590 回答