angular - 打字稿 - 在过滤器中添加动态字段
问题描述
如何在过滤器中动态添加 n 个字段?我想根据我的要求传递 1 个字段或 2 个字段或 n 个字段..
myArray.filter(x => x.field1 === field1Value && x.field2 === field2Value && so on depending on my requirements..);
解决方案
一种方法可以是
let attrValues = [{attr:'name', value:'Marcus'}, { attr:'age', value=24}]
myArray.filter(x=>{
return attrValues.every(item=>x[item.attr] == item.value)
})
推荐阅读
- node.js - Instagram 私人 api 直接消息喜欢/不喜欢
- r - 包反向依赖检查(尤其是在 Windows 上)
- firebase - Firebase 云函数:如何处理由另一个云函数引起的多个触发器?
- android - CardView 中的半透明背景无法正常工作
- frama-c - 如何分析像 open62541 这样的复杂项目?
- azure-cosmosdb - 如何合并一个文档 CosmosDb 的列表
- java - Java内部类使用来存储一个人的多个角色
- python - 为什么 Python 3 for 循环输出和行为不同?
- c# - NEST 会在 elasticsearch 中还是在客户端中进行项目?
- dictionary - 从值中提取字典键