bootstrap3.0 typeahead插件无法正常工作

时间:2013-12-27 17:19:54

标签: javascript twitter-bootstrap bootstrap-typeahead

我正在努力让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;" >

1 个答案:

答案 0 :(得分:1)

正如Marwan所说,Typeahead已从Bootstrap中删除。如果您包含此库,则代码实际上有效:版本2.3.2中的http://getbootstrap.com/2.3.2/assets/js/bootstrap-typeahead.js

这是working fiddle