The following code shows how to create autocomplete from data-source.
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.9.1.js'></script>
<link rel="stylesheet" type="text/css"
href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css">
<script type='text/javascript'
src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){<!--from w ww . j a v a 2 s . c o m-->
$.fn.typeahead.Constructor.prototype.render = function (items) {
var that = this;
items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', item);
i.find('a').html(that.highlighter(item));
return i[0];
});
this.$menu.html(items);
return this;
};
});//]]>
</script>
</head>
<body>
<br />
<div style="background-color: #f5f5f5;" class="bs-docs-example">
<input type="text"
data-source="["Alabama",
"Alaska",
"Arizona",
"Arkansas",
]"
data-items="4" data-provide="typeahead" style="margin: 0 auto;"
class="span3" />
</div>
</body>
</html>