angular - 我正在尝试使用随附的代码制作过滤表,可以吗?
解决方案
首先,请不要附图片,只复制问题中的重要部分代码,选择并使用Ctrl + K格式化(基于图像的问题真的很难阅读)
其次,使用带有两个参数的简单函数,例如
(click)="filterYear(0,20)"
(click)="filterYear(21,30)"
...
同性别
(click)="filterGender('male')"
(click)="filterGender('female')"
(click)="filterGender(null)"
您需要将性别以及最小和最大年份存储在三个变量中
我想你有两个变量“data”和“dataFiltered”。所以你的功能过滤器应该像
filterYear(min:number,max:number)
{
this.min=min;
this.max=max;
this.filter(); //call to the function filter
}
filtergender(gender:any)
{
this.gender=gender
this.filter();
}
filter()
{
this.dataFiltered=this.data.filter(x=>x.year>=min && x.prop<=year &&
(!this.gender || x.gender==this.gender)
}
如果 this.gender 没有值或性别等于 this.gender,则看到最后一个条件为真
注意:我不知道您的数据,所以我想您有一个具有“年份和性别”属性的对象数组
推荐阅读
- python - 如何通过 Python 中的 pandas 库删除 csv 中的重复项?
- javascript - 为什么这个函数会执行多次?
- python - Pandas isin 基于两列
- android - 在 Ubuntu 18.04.3 上安装 kotlin
- python - for循环python中的if语句保存到CSV
- android - 手机静音时如何不播放声音?
- c# - 异步函数同步运行而不是异步
- javascript - 从获取响应 Javascript/Nodejs 创建缓冲区对象
- php - 有没有办法列出所有在某个类别中发布视频的作者并一起显示,比如列表?
- python - 将.txt文件读入字典python