2012-10-22 35 views
1

我实际上是使用来自Twitter引导的Typeahead插件,并且希望在加载服务器中的数据后添加新行。加载Twitter引导类型的源代码后执行函数

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

一旦数据加载,我想添加一个新的行与下拉底部的查询。

这样做的诀窍是什么?

回答

0

u必须做一些修改下面的代码 -

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

现在你的预输入源看起来像这 -
[“值1”,“值2”,“值3”,“值4”, “Value5”,“新线路在这里”]