【发布时间】:2019-05-07 14:59:48
【问题描述】:
我有一个包含两个过滤选项“性别”和“国家”的表格!本质上,过滤器有效,即我单击男性或女性的性别下拉列表,表格显示了所有条目。我的问题是,按照我所做的方式,我总是必须刷新(如重新加载数据)表,然后才能再次过滤。假设我有女性过滤器,我不能直接点击男性来显示男性条目,我必须刷新然后我才能再次过滤。我确信这只是一两行代码的问题,但我似乎无法弄清楚。
下面是我的方法:
filterByGender(event) {
let gender = event;
if (gender === "Male") {
gender = "M";
} else if (gender === "Female") {
gender = "F";
}
let filteredGender = this.customerArray
.filter(customer => customer.gender === gender);
console.log("filteredGender", filteredGender);
this.customerArray = filteredGender;
}
filterByCountry(event) {
let country = event;
let filteredCountry = this.customerArray
.filter(customer => customer.countryCode === country);
this.customerArray = filteredCountry;
}
this.customerArray 是后端所有客户的数组。现在它不能按我想要的方式工作的原因是因为我重新填充了数组,所以我不能做第二个过滤器,但是有什么办法解决这个问题?
【问题讨论】: