我正在使用 React 对 Json 文件进行过滤。如何进行不区分大小写的搜索?
这是我的代码
_handleSearch ({ inputNameValue, inputPriceValue }) {
let list = data.filter(hotel => hotel.name.includes(inputNameValue))
}
最佳答案
如何对两个字符串进行大小写标准化,例如将它们都小写:
请注意,建议在过滤器之外更改输入。
_handleSearch ({ inputNameValue, inputPriceValue }) {
const lowerCased = inputNameValue.toLowerCase();
let list = data.filter(hotel => hotel.name.toLowerCase().includes(lowerCased ))
}
关于reactjs - react : Filter function case insensitive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48979908/