javascript - ramda 过滤器仅返回第一个结果

标签 javascript ramda.js

给定元素上的属性数组(来自控制台窗口) enter image description here

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

执行此操作时:

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

我得到了“name”属性。
enter image description here

当这样颠倒“或”参数时:

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

我得到了“id”属性: enter image description here

过滤器方法应该返回数组中的所有匹配项 - 我错过了什么?**

最佳答案

R.or需要两个 bool 参数,尽管您向它传递了两个返回 bool 值的函数( R.equals )。您应该能够将 R.or 的使用替换为 R.either ,它需要两个像您一样的谓词函数,并且您的过滤器应该执行您期望的操作。

关于javascript - ramda 过滤器仅返回第一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36007146/

相关文章:

javascript - 在 Ramda 中组合函数,每个函数接收相同的值

javascript - 如何处理使用两种不同表单或方法的提交

javascript - 如何使用复选框将 html 标签插入到 div 中?

javascript - 获取数据属性 == 某物的元素

javascript - 如何使用Ramda通过键值查找数组中的匹配对象

javascript - 如何在 vanilla JS 中重写这个 ramda.js 代码

javascript - Ramda帮助: Pointfree implementation w/placeholders to direct arguments

javascript - 免点调试

javascript - 在 jquery 中如何让鼠标悬停和点击一起发挥良好作用?

javascript - 需要在 Azure Devops 中使用 build.yaml 构建 javascript 应用程序