【发布时间】:2019-05-17 19:52:29
【问题描述】:
data:[
{
id:1,
tags:['TagA','TagB','TagC']
},
{
id:2,
tags:['TagB','TagD']
},
{
id:3,
tags:['tagE','tagC']
}
]
filterCondition:{tags:['TagA','TagB']}
Expected Output: [
{
id:1,
tags:['TagA','TagB','TagC']
},
{
id:2,
tags:['TagB','TagD']
}
]
有没有办法在打字稿中使用过滤器方法来实现这一点? 当 tags 字段不是数组但它在数组中时,它是可能的 代码中断。
我试过了,但失败了:
data.filter(o => Object.keys(filterCondition).every(k => filterCondition[k].some(f => o[k] === f)));
【问题讨论】:
-
typescript 是 js 的超集,所以 js 解决方案会起作用,因为它是 js
标签: javascript arrays angular typescript