在某些情况下,通常在从初始搜索缓存值之后,我无法让 mdb_autocomplete 下拉菜单单击一下就关闭。我经常需要双击我的选择才能关闭它。我通过 Ajax 调用服务方法和控制器操作方法动态填充下拉列表中的值,该方法在活动目录中搜索前 30 个名称值。在用户在 mdb_autocomplete 选择框中输入至少 3 个值之前,不会发生回调。下拉列表的回调和填充效果很好,但是选择值之后的点击事件通常不会关闭下拉列表。此外,我们被迫在正常引导库上使用 mdb boostrap。我已经包括了视图,服务,
看法:
<div class="form-group">
<label class="font-weight-bold" for="RequestorSearchInput">Requestor</label>
<input type="text" id="RequestorSearchInput" name="RequestorSearchInput" class="form-control mdb-autocomplete" />
<span id="loading_data_icon"></span>
</div>
服务方式:
public List<string> GetRequestor(string aRequestor)
{
IEnumerable<Dictionary<string, string>> requestorNames;
using (ActiveDirectoryService service = new ActiveDirectoryService(<LDAP Domain Name>))
{
string[] propertiesToLoad = new string[] { "displayName" };
//requestorNames = service.SearchByPartialUsername(aRequestor, propertiesToLoad).Take(30).Union(service.SearchBySurname(aRequestor, propertiesToLoad).Take(30));
requestorNames = service.SearchBySurname(aRequestor, propertiesToLoad).Take(30);
}
return requestorNames.SelectMany(x => x.Values).Where(y => y.IndexOf(",", StringComparison.Ordinal) >= 0).Distinct().ToList();
}
打字稿:
private handleRequestorSearch() {
let options: string[] = new Array();
// @ts-ignore
let searchval = $("#RequestorSearchInput").val().length;
if (searchval >= 3) {
$.ajax({
url: main.getControllerHREF("GetRequestor", "Search"),
method: "POST",
data: {
requestor: $("#RequestorSearchInput").val()
},
async: false,
dataType: "json",
success: function (names) {
$.each(names, function () {
options.push(this);
});
// @ts-ignore
$("#RequestorSearchInput").mdb_autocomplete({
data: options
}).select(function () {
$("#RequestorSearchInput").focus;
});
}
});
}
}