Created
December 6, 2012 09:36
-
-
Save mauromarano/4223256 to your computer and use it in GitHub Desktop.
Esempio typeahead twitter bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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