我试图使搜索不区分大小写,并且尝试了所有在问题中找到的解决方案,但是仍然无法正常工作。这是我现在拥有的代码,但是我希望它能够搜索,无论用户键入的字母是大写还是小写。
loadData: function (filter) {
criteria = filter;
var data = $.Deferred();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Admin/getMultiCentreDeals",
dataType: "json"
}).done(function (response) {
var res = [];
if (criteria.dealTitle !== "") {
response.forEach(function (element) {
if (element.dealTitle.indexOf(criteria.dealTitle) > -1) {
res.push(element);
response = res;
}
}, this);
}
else res = response;
if (criteria.dealSubTitle !== "") {
res = [];
response.forEach(function (element) {
if (element.dealSubTitle.indexOf(criteria.dealSubTitle) > -1)
res.push(element);
}, this);
}
else res = response;
if (criteria.dealURL !== "") {
res = [];
response.forEach(function (element) {
if (element.dealURL.indexOf(criteria.dealURL) > -1)
res.push(element);
}, this);
}
else res = response;
data.resolve(res);
});
return data.promise();
},
},
答案 0 :(得分:1)
不区分大小写的搜索:
loadData: function(filter) {
return $.grep(this.items, function(items) {
return !filter.name||
(items.name.toLowerCase().indexOf(filter.name.toLowerCase()) > -1);
});
}
答案 1 :(得分:0)
var res = [];
if (criteria.HotelName !== "") {
response.forEach(function (element) {
if (element.HotelName.toLowerCase().indexOf(criteria.HotelName.toLowerCase()) > -1) {
res.push(element);
response = res;
}
}, this);
}
else res = response;