My current code looks like this:
$(document).ready(function () {
$('#txtSearchForTrainingFacility').autocomplete({
select: function (event, ui) {
searchCallback(event, ui);
}, // select
source: function (request, response) {
$.ajax({
url: 'http://localhost:49795/Ajax/Search/' + $('#txtSearchForTrainingFacility').val(),
dataType: 'json',
data: {},
success: function (data) {
response( $.map( data, function( item ) {
return {
label: item.Name,
value: item.Value,
id: item.ID
} // return object
})) // response
} // success
}) // ajax
} // source function
}); // autocomplete
}); // document.ready
You can see that in the ajax.success
event function I am mapping returning an object with label
, value
, and id
properties - yet the autocomplete.select
method's ui.item
parameter only contains label
and value
.
What am I doing wrong? How can I get the id
property to appear on the autocomplete.select
's ui.item
object?
the result of the ajax call is a json array, with each element an object that contains the properties
Name
,Value
, andID
.
Note
If you replace the ajax call with a fixed array [{id: 1, label: 'bob', value: 'creep'}, {id: 2, label: 'joe', value: 'friend'}]
then the id
property seem to come through in the select event just fine.