我有初始的数据数组dataToDisplay
和我需要在其中添加过滤数组的数组dataToDisplay
。我曾经用.filter()
这样做:
this.dataToDisplay = this.dataToDisplay.filter((res)=>{
console.log(res);
if(res.type==this.filterArray['typeOfIns'])
{
this.dataToFilter = res;
console.log(this.dataToFilter)
//this.dataToFilter = res;
//console.log(this.dataToFilter)
}
})
我收到一个错误,说:
错误错误:尝试比较"[对象对象]"时出错。仅数组和 允许迭代对象
第 58 行的结果:console.log(this.dataToFilter)
返回正确的数组,但无法显示并绑定到页面中。
dataToDisplay
具有以下结构:
dataToDisplay = [
{id:.., type:.., name:..},
{id:.., type:.., name:..}
]
请尝试以下代码:
this.dataToDisplay = this.dataToDisplay.filter((res)=>{
return res.type==this.filterArray['typeOfIns']
})
这将完成所有工作。