我使用以下代码,它仅适用于案例衰减值, 如果用户使用大写或小写,我想要一些如何克服它 它会起作用,我该怎么做?
oAc.setFilterFunction(function(sValue, oItem) {
debugger;
var val = (oItem.getText().indexOf(sValue) != -1) || (oItem.getAdditionalText().indexOf(sValue) != -1);
return val;
});
在sValue中我得到了值并且val返回true或false 在oItem.getText()中我得到的文本要比较,如果我进入sValue = i 并且oItem.getText()返回索引方法返回true。
答案 0 :(得分:2)
一种简单的方法是在indexOf()
操作
oAc.setFilterFunction(function (sValue, oItem) {
debugger;
sValue = sValue.toLowerCase();
var val = (oItem.getText().toLowerCase().indexOf(sValue) != -1) || (oItem.getAdditionalText().toLowerCase().indexOf(sValue) != -1);
return val;
});
另一种解决方案是使用正则表达式来测试值,而不是使用indexOf
if (!RegExp.escape) {
RegExp.escape = function (value) {
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&")
};
}
oAc.setFilterFunction(function (sValue, oItem) {
debugger;
var regex = new RegExp(RegExp.escape(sValue), 'i');
var val = regex.test(oItem.getText()) || regex.test(oItem.getAdditionalText());
return val;
});
答案 1 :(得分:0)
您可以将文字转换为小写。
oAc.setFilterFunction(function(sValue, oItem) {
debugger;
var val = (oItem.getText().toLowerCase().indexOf(sValue.toLowerCase()) != -1) || (oItem.getAdditionalText().toLowerCase().indexOf(sValue.toLowerCase()) != -1);
return val;
})
答案 2 :(得分:-2)
您可以在名为toLowerCase()或toUpperCase()的String类中查看Java的内置函数
此处有更多信息
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html