1
我在視圖中使用jQuery Auto Complete Plugin作爲文本字段。單一選擇完美。jQuery自動完成插件,多項選擇覆蓋以前的選擇
我正在合併多個選擇,但由於某種原因,如果我選擇多個值,前面的選擇將被覆蓋。
我正在關注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);
}