javascript - Taking an object and using it as a source for autocomplete -
i have need of autocomplete using jquery ui. object have looks this.
"last_name":"a" , "first_name":"a" , "email_addr":"a@a.com"
i have no command on this. it's how info formatted when returned database query. want utilize source autocomplete. have this:
$( "#inputvisitorlastname" ).autocomplete({ source: visitorsdrop });
where visitorsdrop list of objects. best way approach , how go doing that? there way don't know of alter objects include value , label tags need? should seek turn objects strings? google turns confusing results on how that, well. tried this:
var intarr = [visitorsdrop.last_name];
and array makes undefined. i'm pretty new javascript , not sure what's going wrong; can help me out?
edit: since asked, visitorsdrop assigned value through json , vb.net, makes database query; it's made this:
var visitorsdrop = that.getvisitors();
need turn array of objects array of strings? sounds job map
!
$( "#inputvisitorlastname" ).autocomplete({ source: visitorsdrop.map(function(o) { homecoming o.last_name; }) });
foo.map(...)
builds new array passing each element of foo
(an existing array) function , using homecoming value of each function phone call value place in new array. so, here, each object in visitorsdrop
passed in o
function, , new array filled last_name
value of each object.
to back upwards older browsers, may need supply polyfill.
javascript jquery jquery-ui
No comments:
Post a Comment