用两个参数\参数过滤 [英] Filter with two arguments\parameters
本文介绍了用两个参数\参数过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应该返回列表的方法. 我想通过两个参数而不是一个来过滤数据. 到目前为止,我已经完成了以下操作,但这是不想要的结果,所以我可能做错了一些事情
I have a method that should return a list. I would like to filter the data by two parameters and not one. So far I have done the following but that's an unwanted result so I've probably done something wrong
performFilterByRunnerName(
filterByCompetition: string, filterByRunnerName: string
): IRunners[] {
return this.runners
.filter(x => x.runnerName === filterByRunnerName)
.filter(x => x.competitionId === filterByCompetition);
}
推荐答案
使用&&
运算符
performFilterByRunnerName(
filterByCompetition: string, filterByRunnerName: string
): IRunners[] {
return this.runners
.filter(x => x.runnerName === filterByRunnerName && x.competitionId === filterByCompetition);
}
这篇关于用两个参数\参数过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文