【问题标题】:bootstrap3.0 typeahead plugin not workingbootstrap3.0 预输入插件不起作用
【发布时间】:2013-12-27 17:19:53
【问题描述】:

我正在尝试让 typeahead 自动完成工作,但我没有看到它正在工作。

jsfiddle

$('#selectAgent').typeahead({
source: function(query, process) {
    objects = [];
    map = {};
    var data = [{"id":1,"label":"machin"},{"id":2,"label":"truc"}] // Or get your JSON dynamically and load it into this variable
    $.each(data, function(i, object) {
        map[object.label] = object;
        objects.push(object.label);
    });
    process(objects);
},
updater: function(item) {
    $('id').val(map[item].id);
    return item;
}
}); 

//HTML:

 <input name="selectAgent" type="text" id="selectAgent" class="validate[required] text-input form-control" data-prompt-position="topLeft:70" placeholder="type &quot;Agent name or id &quot;" title="type &quot;Agent name or id &quot;" >

【问题讨论】:

    标签: javascript twitter-bootstrap bootstrap-typeahead


    【解决方案1】:

    正如 Marwan 所指出的,Typeahead 已从 Bootstrap 中删除。如果您包含此库,您的代码实际上可以工作:http://getbootstrap.com/2.3.2/assets/js/bootstrap-typeahead.js 来自版本 2.3.2。

    这是working fiddle

    【讨论】:

    • 我用的是bootstrap3.0和twitter.github.io/typeahead.js最新的JS文件。
    • 对不起,我在那里有一个 console.log 如果你没有控制台会导致它失败,更新我的链接。
    • 我已接受您的回答。谢谢!。我已将代码复制到我的本地工作区,但它不工作。它与 ny js 文件冲突吗?我有 jquery 1.10.2、bootstrap.js v3.0.0 和 bootstrap-typeahead.js v2.3.2
    • 如果您要使用新的 typeahead.js,您需要为此使用适当的格式。你可以去这里twitter.github.io/typeahead.js/examples 获取语法示例。
    • 我已经从您提供的 url 下载了 js 文件。getbootstrap.com/2.3.2/assets/js/bootstrap-typeahead.js。它正在工作,但不在我的工作空间中。
    猜你喜欢
    • 1970-01-01
    • 2014-04-02
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多