如何在 Jsgrid 过滤器中使搜索不区分大小写?
How to make the search case insensitive in Jsgrid filter?
我正在尝试使搜索不区分大小写,并且我已经尝试了问题中找到的所有解决方案,但仍然无法正常工作。这是我现在拥有的代码,但我希望它能够搜索,无论用户输入的字母是大写还是小写。
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();
},
},
不区分大小写的搜索:
loadData: function(filter) {
return $.grep(this.items, function(items) {
return !filter.name||
(items.name.toLowerCase().indexOf(filter.name.toLowerCase()) > -1);
});
}
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;
我正在尝试使搜索不区分大小写,并且我已经尝试了问题中找到的所有解决方案,但仍然无法正常工作。这是我现在拥有的代码,但我希望它能够搜索,无论用户输入的字母是大写还是小写。
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();
},
},
不区分大小写的搜索:
loadData: function(filter) {
return $.grep(this.items, function(items) {
return !filter.name||
(items.name.toLowerCase().indexOf(filter.name.toLowerCase()) > -1);
});
}
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;