[英]How to show autocomplete from more than one column?
This code returns only the autocomplete from one column, and my logic is to get it from two columns. 这段代码仅从一列返回自动完成功能,而我的逻辑是从两列中获取自动完成功能。 I want to know what is the problem.
我想知道是什么问题。 Please, if any one knows the answer please help me.
请,如果有人知道答案,请帮助我。
Thanks! 谢谢!
public JsonResult SearchFromTable(string name)
{
AccountingDataLayer.AccountingSMSEntities context = new AccountingDataLayer.AccountingSMSEntities();
var search = (from s in context.Products
where s.Name == name || s.FullCode == name
select new{s.FullCode , s.Name , s.Description });
return Json(search, JsonRequestBehavior.AllowGet);
}
public JsonResult AutoCompleteProductName(string term , string t)
{
AccountingDataLayer.AccountingSMSEntities context = new AccountingDataLayer.AccountingSMSEntities();
var result = (from p in context.Products
where p.Name.ToLower().Contains(term.ToLower()) || p.FullCode.ToLower().Contains(t.ToLower())
select new { p.Name , p.FullCode }).Distinct();
return Json(result, JsonRequestBehavior.AllowGet);
}
$("#search").autocomplete({
source: function (request, response) {
$.ajax({
url: "/InVoiceStock/AutoCompleteProductName",
type: "POST",
dataType: "json",
data: { term: request.term , t: request.t },
success: function (data) {
response($.map(data, function (item , t) {
return { label: item.Name, value: item.Name, label: t.FullCode, value: t.FullCode };
}))
}
})
},
messages: {
noResults: "", results: ""
}
});
});`
You have unnecessarily created a whole set of t
variables. 您不必要地创建了一整套
t
变量。 The request object will have only one term
property, which refers to the value currently in the text input. 该请求对象将仅具有一个
term
属性,该属性引用文本输入中当前的值。 So the request.t
will be undefined here 所以
request.t
在这里将是未定义的
data: { term: request.term , t: request.t }
Moving forward, in the action method string t
will be null and will not be used in filtering 向前移动,在操作方法中,
string t
将为null,并且不会在过滤中使用
var result = (from p in context.Products
where p.Name.ToLower().Contains(term.ToLower()) || p.FullCode.ToLower().Contains(t.ToLower())
select new { p.Name , p.FullCode }).Distinct();
To correct it, in the where clause use term
in both conditions and remove unnecessary references to t
要更正它,请在where子句中在两个条件中都使用
term
并删除对t
不必要引用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.