【问题标题】:Ionic, javascript search items in lowercase离子,小写的javascript搜索项目
【发布时间】:2021-12-22 07:50:26
【问题描述】:

有一个时间列表,大写。如果输入文本是小写的,我该如何找到它们?

例如:巴塞罗那,当输入“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;
    }
  }

【问题讨论】:

标签: javascript ionic-framework ionic4


【解决方案1】:

这个怎么样

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

先将文本小写以节省一些循环

【讨论】:

    猜你喜欢
    • 2013-08-18
    • 2014-03-09
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多