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=[&quot;neuchatel&quot;,&quot;moutier&quot;]"> 

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="[&quot;/foo.html&quot;,&quot;http://www.google.com&quot;,&quot;/about.html&quot;]"> 

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;     } }); 

demo on bootply


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -