【发布时间】:2013-12-27 17:19:53
【问题描述】:
我正在尝试让 typeahead 自动完成工作,但我没有看到它正在工作。
$('#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 "Agent name or id "" title="type "Agent name or id "" >
【问题讨论】:
标签: javascript twitter-bootstrap bootstrap-typeahead