首页 > 解决方案 > 离子,小写的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;
    }
  }

标签: javascriptionic-frameworkionic4

解决方案


这个怎么样

this.locations = text ? this.old_locations
  .filter(element => element.title.toLowerCase().includes(text.toLowerCase())) :
  this.old_locations;

通过首先小写文本来节省一些循环


推荐阅读