Utilizing Bootstrap's typeahead as a search function -
i've got typeahead working fine, inexperienced javascript understand how turn typed results link.
<input type="text" class="span3" data-provide="typeahead" placeholder="city search:" data-items="6" autocomplete="off" data-source=["neuchatel","moutier"]"> so, want know how turn strings data-source links other pages. simple.
thanks!
you can turn strings links easily..
<input type="text" data-provide="typeahead" data-source="["/foo.html","http://www.google.com","/about.html"]"> are looking take link input , navigate selected page?
edit: navigate item selected in typeahead..
in case you'd define object map contain keys (label) , values (url) like..
var data = { "login":"/login", "home":"/", "user":"/user", "tags":"/tags", "google":"http://google.com" }; then you'd initiate typeahead. source , updater functions defined handle 1) creating typeahead data source array map object, , 2) navigate appropriate url when item selected..
$('.typeahead').typeahead({ minlength:2, updater: function (item) { /* navigate selected item */ window.location.href = data[item]; }, source: function (typeahead, query) { var links=[]; (var name in data){ links.push(name); } return links; } });
Comments
Post a Comment