ramda 过滤器只返回第一个结果

ramda filter only returning first result

给定一个元素的属性数组(来自控制台 window)

我需要检索所有'id'或'name'属性

执行此操作时:

R.filter(R.where({name: R.or(R.equals('name'), R.equals('id'))}), attr)

我得到 'name' 属性。

当这样颠倒 'or' 参数时:

R.filter(R.where({name: R.or(R.equals('id'), R.equals('name'))}), attr)

我得到 'id' 属性:

filter 方法应该在 array 中返回所有 匹配项 - 什么我是不是不见了?**

R.or is expecting two boolean arguments, though you're passing it two functions (R.equals) that return boolean values instead. You should be able to swap out the use of R.or with R.either,它有两个像你一样的谓词函数,你的过滤器应该做你期望的。