javascript - Twitter Typehead, listing object arrays -
i having problem using twitter typehead object array.
please view jsbin here http://jsbin.com/buyudaq/edit?html,js,console,output
following serialised object array
var phonenumbers = { "data": [ { "phone": "+1 (923) 562-3211" }, { "phone": "+1 (924) 431-3216" }, { "phone": "+1 (932) 411-2223" }, { "phone": "+1 (857) 584-3623" }, { "phone": "+1 (914) 472-3779" }, { "phone": "+1 (876) 554-3637" }, { "phone": "+1 (916) 537-3873" } ] };
i have modified code, instead of passing object, passing array 'local' option should work. since source array of object, better specify property value show adding 'display' option.
var phones = new bloodhound({ datumtokenizer: bloodhound.tokenizers.obj.whitespace('phone'), querytokenizer: bloodhound.tokenizers.whitespace, identify: function(obj) { return obj.phone; }, local: phonenumbers.data }); $('.typeahead').typeahead({ hint: true, highlight: true, minlength: 1 },{ name: 'phones', source: phones, display: 'phone' });
Comments
Post a Comment