Javascript Jqgrid ui自动完成:禁用区分大小写
在我的JQgrid中,我有一个区分大小写的完整列 例如,我的网格中有两个项目:Ivan和Ivan,如果我键入“i”,autocomplete将只返回Ivan。 我曾尝试在源代码中创建一个函数:但我失败了,因为我的ajax调用总是返回object而不是item。有什么想法吗 自动完成代码:Javascript Jqgrid ui自动完成:禁用区分大小写,javascript,jquery,jquery-ui,jqgrid,autocomplete,Javascript,Jquery,Jquery Ui,Jqgrid,Autocomplete,在我的JQgrid中,我有一个区分大小写的完整列 例如,我的网格中有两个项目:Ivan和Ivan,如果我键入“i”,autocomplete将只返回Ivan。 我曾尝试在源代码中创建一个函数:但我失败了,因为我的ajax调用总是返回object而不是item。有什么想法吗 自动完成代码: $(elem).autocomplete({ delay: 0, minLength: 0,
$(elem).autocomplete({
delay: 0,
minLength: 0,
source: function (req, response) {
alert(req);
$.ajax({
mtype: "post",
url: '@Url.Action("GetBrands")',
dataType: "json",
async: false,
cache: false,
data: { term: req },
success: function (data) {
alert(data);
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp("^" + re, "i");
response($.grep(data, function (item) { return matcher.test(item.value); }));
}
});
},
控制器端代码:
public virtual JsonResult GetBrands(string term)
{
if (term == null) term = string.Empty;
var vendorId = _service.GetVendorIdByUsername(GetUserName());
var brands = _service.GetBrandsByVendor(vendorId);
var brand = new BrandsViewModel();
brand.BrandName = "Opret ny Brand...";
brands.Add(brand);
foreach (var brandsViewModel in brands)
{
if (brandsViewModel.BrandName == "Intet")
{
brandsViewModel.BrandName = "";
}
}
return Json((from item in brands
where item.BrandName.Contains(term)
select new
{
value = item.BrandName
//votes = item.Votes,
}).ToArray(),
JsonRequestBehavior.AllowGet);
}
在竞赛时将其全部转换为一种情况:
public virtual JsonResult GetBrands(string term)
{
if (term == null) term = string.Empty;
term = term.ToLower();
var vendorId = _service.GetVendorIdByUsername(GetUserName());
var brands = _service.GetBrandsByVendor(vendorId);
var brand = new BrandsViewModel();
brand.BrandName = "Opret ny Brand...";
brands.Add(brand);
foreach (var brandsViewModel in brands)
{
if (brandsViewModel.BrandName == "Intet")
{
brandsViewModel.BrandName = "";
}
}
return Json((from item in brands
where item.BrandName.ToLower().Contains(term)
select new
{
value = item.BrandName
//votes = item.Votes,
}).ToArray(),
JsonRequestBehavior.AllowGet);
}
嗯,我考虑过,但想在客户端做。但我坚持这一点。谢谢