gpt4 book ai didi

autocomplete - 如何在 Ionic 4 的搜索栏上使用自动完成功能?

转载 作者:行者123 更新时间:2023-12-03 17:39:32 27 4
gpt4 key购买 nike

我正在寻找一些示例,但看不到任何人在谷歌上搜索它,我想要的是硬编码 2 或 3 个单词,非常感谢。我必须在 ionic 3 上寻找吗?还是在 angular2 中更好?

最佳答案

在您的 html 文件中:

     <ion-searchbar type="text" debounce="500" (ionChange)="getItems($event)"></ion-searchbar>
<ion-list *ngIf="isItemAvailable">
<ion-item *ngFor="let item of items">{{ item }}</ion-item>
</ion-list>

在您的 ts 文件中:

     // Declare the variable (in this case and initialize it with false)
isItemAvailable = false;
items = [];

initializeItems(){
this.items = ["Ram","gopi", "dravid"];
}

getItems(ev: any) {
// Reset items back to all of the items
this.initializeItems();

// set val to the value of the searchbar
const val = ev.target.value;

// if the value is an empty string don't filter the items
if (val && val.trim() !== '') {
this.isItemAvailable = true;
this.items = this.items.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
} else {
this.isItemAvailable = false;
}
}

关于autocomplete - 如何在 Ionic 4 的搜索栏上使用自动完成功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54998476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com