我无法在MVC4中的自动填充文本框中选择特定项目。 我正在获取匹配数据,我将其附加到div(showresults)。但无法选择一个项目。请有人帮助我。如果需要更多信息,请告诉我。 下面是jquery中的代码:
$("#search").autocomplete({
source: function (request, response) {
var customer = new Array(); alert(request);
var result;
$.ajax({
async: false,
cache: false,
type: "POST",
url: "/Enrollment/Member/GetNamesList",
data: { "term": request.term },
success: function (data)
{
$('#showresults ul').html('');
$('').appendTo($('#showresults ul'));
$(data).each(function () {
$('<li><a href="" title="' + this.FirstName + '" data-val="' + this.UHID + '">' + this.FirstName + '</a></li>').appendTo($('#showresults ul'));
});
},
select: function (event, ui) {
alert("select");
},
error: function (msg)
{
alert("error occured");
}
});
}
})
答案 0 :(得分:0)
If you are getting data as you mentioned, then please check the fiddle below, I'm able to select the item.
var data = [
{
"id": "1001",
"value": "Habib"
},
{
"id": "1002",
"value": "Habib2"
}];