Hy! I\'m using twitter bootstraps typeahead:
I\'m calling a page that returns a response with json_encode the page returns a name and an ID,
I want that the type
My solution is:
var productNames = new Array();
var productIds = new Object();
$.getJSON( '/getAjaxProducts', null,
function ( jsonData )
{
$.each( jsonData, function ( index, product )
{
productNames.push( product.id + product.name );
productIds[product.id + product.name] = product.id;
} );
$( '#product' ).typeahead( { source:productNames } );
} );
In my case, product.id is a code, so it is useful to display it in typeahead control. In this way i avoided duplicated names risk.