Skip to content

Instantly share code, notes, and snippets.

@mauromarano
Created December 6, 2012 09:36
Show Gist options
  • Save mauromarano/4223256 to your computer and use it in GitHub Desktop.
Save mauromarano/4223256 to your computer and use it in GitHub Desktop.
Esempio typeahead twitter bootstrap
$(function(){
// nome della classe di input ad esempio:
// <input type="text" class="ajax-typeahead">
$('.ajax-typeahead').typeahead({
// specifico da dove prendere i dati
source: function(typeahead,cb){
// questo url ad esempio ritorna un oggetto json
return $.get('http://localhost:8888/oveo/public/index.php/players/' + typeahead, function(data){
// costruisco un array a partire dall'oggetto json
var players = [];
for(i=0; i<data.length; i++){
players.push(data[i].nome + ' ' + data[i].cognome);
}
// ritorno l'array
return cb(players);
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment