我想在多个字段中搜索inputSearchString并检查它是否包含特定值,如果存在则应返回匹配结果。它应该根据id,colorCode和pattern(以及说明)进行过滤。很少的帮助将不胜感激。有没有最好的解决方案?
const inputTextSearch = "GR"
const recommended = [{'id':'DHT-123', 'colorCode': 'Green', 'pattern': { 'description': 'SOLID'}},
{'id':'DHT-321', 'colorCode': 'Green', 'pattern': { 'description': 'SOLID'}},
{'id':'DHT-444', 'colorCode': 'RED', 'pattern': { 'description': 'SOLID'}},
{'id':'DHT-555', 'colorCode': 'YELLOW', 'pattern': { 'description': 'PLAID'}},
{'id':'DHT-666', 'colorCode': 'YELLOW', 'pattern': { 'description': 'DARK'}}
];
const result = recommended.filter(it => it.id.toUpperCase().includes(inputTextSearch.toUpperCase()) || it.colorCode.toUpperCase().includes(inputTextSearch.toUpperCase()) || it.pattern.description.toUpperCase().includes(inputTextSearch.toUpperCase()));
console.log('result is', result);