在下面的函数中,我试图通过连接tmp数组的值来构建filteredProducts数组。 tmp数组包含元素,但在连接之后,filteredProducts数组为空。
假设布尔变量refineCriteria.bosch为真;
filterProducts(refineCriteria: Refine) {
this.filteredProducts = [];
let tmp = [];
let filtered = false;
if(refineCriteria.bosch) {
tmp = this.products.filter(product => product.brand == "Bosch");
this.filteredProducts.concat(tmp);
filtered = true;
console.log("tmp = " + tmp);
console.log("this.filteredProducts = " + this.filteredProducts);
}
if(!filtered) {
this.filteredProducts = this.products;
}
console.log("filteredProducts = " + this.filteredProducts);
this.filteredProductsEvent.emit(this.filteredProducts);
}