我在文本字段的视图中使用jQuery Auto Complete Plugin。单选完美。
我正在合并多项选择,但由于某种原因,如果我选择多个值,之前的选择会被覆盖。
我按照jQuery Plugin Tutorials中的示例进行操作。
$("#ServiceEntryFilter_System").autocomplete({
source: function (request, response) {
$.ajax({
url: serviceentrySystemURL, type: "POST", dataType: "json",
minLength: 0,
data: { searchText: extractLast(request.term), maxResult: 100, instrumenttype: userroleid },
success: function (data) {
response($.map(data, function (item) {
return { value: item }
}))
}
})
},
focus: function () {
// prevent value inserted on focus
return false;
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
});
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
[HttpPost]
public JsonResult FindSystem(string searchText, int maxResult, string instrumenttype)
{
int UserRoleID = AccessHelper.GetUserRoleID(User.Identity.Name);
var result = RunLog.Domain.Lists.GlobalList.GetInstrumentSystem(searchText, maxResult, instrumenttype);
return Json(result);
}