私の現在のコードは次のようになります。
$(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
イベント関数では、 、、およびプロパティajax.success
を持つオブジェクトを返すようにマッピングしていますが、メソッドのパラメーターには と のみが含まれていることがわかります。label
value
id
autocomplete.select
ui.item
label
value
私は何を間違っていますか?id
プロパティをautocomplete.select
のui.item
オブジェクトに表示するにはどうすればよいですか?
Name
ajax 呼び出しの結果は json 配列であり、各要素はプロパティ、Value
、およびを含むオブジェクトですID
。
注:[{id: 1, label: 'bob', value: 'creep'}, {id: 2, label: 'joe', value: 'friend'}]
ajax 呼び出しを固定配列に
置き換えるとid
、select イベントでプロパティが問題なく通過するように見えます。