オートコンプリートを実装したテキストボックスがあります。はい、これ。
<input id="txtcity" />
$("#txtcity").autocomplete({
source: function (request, response) {
$.ajax({
url: '@Url.Action("CityLookup", "PatientDemographic", "")', type: "POST", dataType: "json",
data: { searchText: request.term, maxResults: 10 },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Text, value: item.Text, id: item.Value }
}))
}
})
},
select: function (event, ui) {
$("#CityCode").val(ui.item.id);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
これは、「Apple」、「Banana」、「Cabbage」の 3 つの結果を返します。レンダリング中にデフォルト値を「バナナ」に設定するにはどうすればよいですか? つまり、text="バナナ" value="2"?