JavaScript按数组的所有值进行筛选
下面是我的代码和我尝试的内容:JavaScript按数组的所有值进行筛选,javascript,arrays,filter,Javascript,Arrays,Filter,下面是我的代码和我尝试的内容: filterPrestationsByServiceSelected(arrayOfServices) { console.log(arrayOfServices); // ['Repassage', 'Couture'] this.filteredPrestationsByService = this.filteredPrestations.filter(item => item.service.name.includes(arrayOfS
filterPrestationsByServiceSelected(arrayOfServices) {
console.log(arrayOfServices); // ['Repassage', 'Couture']
this.filteredPrestationsByService = this.filteredPrestations.filter(item => item.service.name.includes(arrayOfServices.values()));
},
我想筛选此.filteredPrestations的所有项目,其中
服务名称
包含阵列服务
的值
有人知道我能做什么吗?
谢谢你 你能试试这个代码吗。我认为这个代码会起作用
filterPrestationsByServiceSelected(arrayOfServices) {
console.log(arrayOfServices); // ['Repassage', 'Couture']
this.filteredPrestationsByService = this.filteredPrestations.filter(item => arrayOfServices.includes(item.service.name));
},
Remove.values()返回您不需要的迭代器
filterPrestationsByServiceSelected(arrayOfServices) {
console.log(arrayOfServices); // ['Repassage', 'Couture']
this.filteredPrestationsByService = this.filteredPrestations.filter(item => item.service.name.includes(arrayOfServices));
}
您必须将列表中的项目与其他项目进行比较。因此,您必须对一个数据结构的每个元素与另一个进行比较。由于您正在比较阵列,因此应该这样做:
filterPrestationsByServiceSelected(arrayOfServices) {
console.log(arrayOfServices); // ['Repassage', 'Couture']
this.filteredPrestationsByService = this.filteredPrestations.filter(item => arrayOfServices.find(e => e === item.service.name))
},
这样,您可以逐个比较元素。您可以添加一个示例数组吗?['Repassage','Couture','Automobile']删除结尾处的.value
arrayOfServices.values()
this.filteredrestationsbyservice=this.filteredrestations.filter(item=>arrayOfServices.includes(item))代码>?哇!那太好了@谢谢你!