【问题标题】:Execute a function after the source of Twitter bootstrap typeahead is loaded在加载 Twitter bootstrap typeahead 的源之后执行一个函数
【发布时间】:2012-10-12 10:19:35
【问题描述】:

我实际上正在使用来自 Twitter bootstrap 的插件 Typeahead,我想在加载来自我的服务器的数据后添加一个新行。

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

加载数据后,我想在下拉列表末尾添加一个带有查询的新行。

这样做的诀窍是什么?

【问题讨论】:

    标签: twitter-bootstrap typeahead bootstrap-typeahead


    【解决方案1】:

    你必须对以下代码做一些修改 -

    // 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","这里换行"]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多