我目前正在尝试让 kendo ui 自动完成来显示结果,即使用户输入了名字和名字。目前,如果自动完成包含名字或第二个名字,我的代码正在工作。我希望自动完成功能仍然显示结果,例如,如果输入了“Peter S”,它仍然会显示“Peter Smith”和“Peter Samsung”的结果。如果有人可以查看我的代码并指出我正确的方向,那就太好了。我在这方面花了很多时间,我想我可能采取了错误的方法。
下面的代码:
$("#FeeEarnerEmailSend").kendoAutoComplete({
dataSource: new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: "/" + prefix + "/api/Session/GetEmployees",
parameterMap: function () {
return { id: $("#FeeEarnerEmailSend").data("kendoAutoComplete").value() };
}
}
}),
dataTextField: 'FullName',
filter: "contains",
//placeholder: "Search...",
minLength: 3,
suggest: true,
select: function (e) {
var employeeAutoComplete = e.sender;
// this var is used in the Search button click event
selectedEmployeeDataItem = employeeAutoComplete.dataItem(e.item.index());
},
change: function () {
if ($.trim($("#FeeEarnerEmailSend").val()) == "") {
selectedEmployeeDataItem = null;
}
},
dataBound: function (e) {
selectedEmployeeDataItem = e.sender.dataItem(0);
}
});
这是我的 Csharp 代码,我认为问题可能出在我的 linq 中,需要编辑才能实现这一点?
[HttpGet]
[Route("api/Session/GetEmployees")]
public IHttpActionResult GetEmployees(string id)
{
logger.Trace("Get Employees - {0} - based on prefix", id);
try
{
DirectoryContext context = new DirectoryContext(new Uri(ConfigurationManager.AppSettings["DirectoryServiceUrl"]));
var result = from q in context.Employees
where q.Surname.Contains(id) || q.KnownAs.Contains(id)
orderby q.Surname, q.KnownAs
select new
{
NetworkId = q.NetworkID,
FullName = String.Format("{0} {1}", q.Surname.ToUpper(), q.KnownAs),
EmailAddress = q.EmailAddress
};
logger.Info("Returning Employees - {0}", id);
return Ok(result.ToList());
}
catch (Exception ex)
{
logger.Error(ex.Message, ex);
return InternalServerError(ex);
}
}