javascript - 离子,小写的javascript搜索项目
问题描述
有一个时间列表,大写。如果输入文本是小写的,我该怎么做才能找到它们?
例如:巴塞罗那,输入“bar”时,找到它。尝试使用 .lowercase() 但不起作用
onSearch(text){
if(text){
const filter_data=this.old_locations.filter((element) => element.title.includes(text));
this.locations=filter_data;
}else{
this.locations=this.old_locations;
}
}
解决方案
这个怎么样
this.locations = text ? this.old_locations
.filter(element => element.title.toLowerCase().includes(text.toLowerCase())) :
this.old_locations;
通过首先小写文本来节省一些循环
推荐阅读
- amazon-web-services - 将 OpenAPI 组件与 AWS API Gateway 结合使用
- c# - 二叉树节点是否通过引用传递?
- javascript - 未定义的 JS 密码生成器
- python - Python Pandas:列中的 set_index 创建我无法删除的空行
- reactjs - MUI Box 组件有什么用?
- python - MongoDB - 聚合以提取唯一文档
- regex - 无法使用 Hive Regex Serde 解析字符串
- mongodb - 在centos 7上安装mongodb时如何处理这个问题?
- python - 将时间从 excel 转移到 Pandas
- python - 是否可以在 Python 中使用 NLTK 从文本中删除句子?