dimanche 1 février 2015

JQuery UI Autocomplete shows [Object object] in textbox while scrolling the menu


I have a textbox on a form that I have attached a jquery ui autocomplete to it like this :



$("#recieverNumber").autocomplete({
source: function (request, response) {
$.ajax({
dataType: "json",
type: 'Get',
url: myServiceUrl,
success: function (data) {
$('input.suggest-user').removeClass('ui-autocomplete-loading'); // hide loading image
var result = [];
data.forEach(function (value, index) {
result.push({ value: value, label: value.Name });
});
response(result);
},
error: function (data, err, message) {
$('input.suggest-user').removeClass('ui-autocomplete-loading');

}
});
},
messages: {
noResults: '',
results: function () { }
},
select: function (event, ui) {
recievers.push(ui.item.value);
notifyRecieversChanged();
$(this).val('');
return false;
}
});


As you can see I am getting its source from a server side service and then I build an array of objects with value and label.Everything is working fine but whenever there are more than one item in autocomplete menu and I want to scroll the menu to find the desirable item I see [Object object] in textbox instead of the label of the item. Am I doing something wrong ?





Aucun commentaire:

Enregistrer un commentaire