ionic-framework - 通过离子搜索栏进行手风琴式下拉过滤
问题描述
嗨,我刚刚按照教程博客链接创建了离子手风琴下拉菜单,该链接使用小部件创建手风琴下拉菜单,下面是该博客的链接。
http://masteringionic.com/blog/2019-01-27-creating-a-simple-accordion-widget-in-ionic-4/
更新:这是我的项目演示链接https://stackblitz.com/github/dSaif/search-accordion 一切正常,但我想在手风琴顶部添加 Ion-searchbar 以便通过输入过滤下拉列表文本。
请帮助我,我该怎么做。谢谢你。
解决方案
您将不得不在主页中创建一个变量来存储过滤结果。然后你需要有一个过滤功能,它将从搜索栏中获取输入并过滤你的主列表。请记住,您不应将新变量设置为主列表,这可能会由于对象引用而导致问题。
所以你应该有类似的东西
在你的 html
<ion-searchbar placeholder="Search a name." [(ngModel)]="searchValue" (ionChange)="filterList()"></ion-searchbar>
在你的 ts 文件中
searchValue: string = '';
filteredList: Array<{ name: string, description: string, image: string }> = this.technologies;
// function called in the html whenever you change the ion searchbar value
private filterList(){
//Make a variable so as to avoid any flashing on the screen if you set it to an empty array
const localFilteredList = []
this.technologies.forEach(currentItem => {
//here goes your search criteria, in the if statement
if(currentItem.name && currentItem.name.toLowerCase().includes(this.searchValue.toLowerCase())) {
localFilteredList.push(currentItem);
}
});
//finally set the global filter list to your newly filtered list
this.filteredList = localFilteredList;
}
您还需要确保引用 filterList 变量而不是当前引用的变量。
推荐阅读
- gulp - 使用 Gulp.src 复制隐藏文件夹
- reactjs - 如何在 React 项目中添加 p5.clickable 和 p5.gui 等 p5.js 社区库?
- javascript - React + Firebase:提交按钮未触发?
- ruby - Ruby on Rails 通过表单错误将对象添加到数据库
- vba - DoCmd.OpenQuery 位于何处
- mysql - 从 nginx conf 文件调用 mysql DB
- wordpress - 在 Woocommerce 侧边栏区域上方移动 Woocommerce 特色类别图片
- sql - Power BI 报表生成器指标公式
- r - 如何在 floor_date 函数后每 8 行检查一次时间是否相似(并在需要时进行更正)
- python - 在 VSCode 终端中添加 Conda 环境