i have an array of products here it is
let products=[
{id:1,category:[23,34],subcategory:[45,67],company:[56,78]}
{id:2,category:[46,19],subcategory:[89,645],company:[16,88]}
]
and here is my dynamic filter array which i have to apply
let filter=[
{key:"category",values:[19]}
{key:"company",values:[88,16]}
]
how can i dynamically filter the products array via rxjs
here is my code which is working for only one filter , but i need for dynamicacally coming more then 1
here is my code for 1 filter i gave the type e.g
type="category"
values=[18,19]
products.pipe(
flatMap(response => response),
filter(
(product: any) => {
return product[type].find((catnum) => values.includes(catnum))
}
), toArray()
).subscribe(data => {}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…