I am trying to get autocomplete working working with JQuery UI, but I am having trouble when I try and pass in a label & value object.
var people = [];
var test = new Array();
var obj = jQuery.parseJSON(data);
$.each(obj.data, function(i,person){
people[people.length] = {
label: person.id,
value: person.name
};
test.push(person.name);
});
$("#friend").autocomplete({
source: test,
select: function(event, ui) {
alert(ui.item.id);
}
});
When I use the 'test' array it is working correctly, but when I try and use the people object nothing seems to be working, an no JS errors either.
What am I missing?
[]vsnew Array()andperson[person.length]vs.push()?input id="friend"on the page?