简体   繁体   English

Ionic 3中文搜索栏

[英]Ionic 3 Search bar in Chinese Language

I'm working to build a search bar to able filter the items based on its chinese name inserted. 我正在构建一个搜索栏,以能够根据插入的中文名称过滤项目。 Now I'm able to search based on its english name rather than chinese language. 现在,我可以根据其英文名称而不是中文进行搜索。

How should I work on chinese text searching? 我应该如何进行中文文本搜索?

Output: 输出: 在此处输入图片说明

Source Code: (HTML) 源代码:(HTML)

<ion-toolbar>
    <ion-searchbar aria-placeholder="search" 
                  [(ngModel)]="queryText"
                  (ionInput)="updateText()">
    </ion-searchbar>
  </ion-toolbar>
  <ion-item >

    <ion-label>Name</ion-label>
    <ion-label>Description</ion-label>
    <ion-label>Chinese Name</ion-label>
</ion-item>

<ion-item *ngFor="let item of filtered" >
  <ion-label>{{item.name}} </ion-label>
  <ion-label>{{item.description}} </ion-label>
  <ion-label>{{item.chinese}} </ion-label> 
</ion-item> 

(Filter Function) in English on fd.name properties fd.name属性上的(筛选器功能)英文

updateText(){
    if (this.queryText == ""){ //if no text insert then display all
      this.filtered = this.food; // Original array with food elements can be [] also
    }
    else{
      this.filtered = this.food.filter((fd) => {
        return fd.name.toLowerCase().indexOf(this.queryText.toLowerCase()) > -1; //filter food.name
      })
    }

Should I change the fd.name properties into fd.chinese name? 我应该将fd.name属性更改为fd.chinese名称吗?

if you wanna search with Chinese text, you must use the original list first, because when you start search, the code executes twice, first search text form is Pinyin, and then Chinese text. 如果要使用中文文本进行搜索,则必须首先使用原始列表,因为当您开始搜索时,代码将执行两次,首先是搜索文本形式是拼音,然后是中文文本。 if you don't recover the list, you cannot get the result filter. 如果您不恢复列表,则无法获得结果过滤器。 for example: 例如:

 if(this.searchQuery && this.searchQuery.trim() != ''){
      this.projectTimeLists = this.getBackUpProjectLists();
      this.projectTimeLists = this.projectTimeLists.filter((project) => {
        return (project.F_Name.toLowerCase().indexOf(this.searchQuery.toLowerCase()) != -1);
      });
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM