2 回答
TA贡献1836条经验 获得超3个赞
像这样的东西:
R.filter(
R.allPass([
R.propEq("published", false),
R.pathEq(["tags", "visibility"], "myself")
])
)(articles);
TA贡献1829条经验 获得超4个赞
您可以使用规范对象:
const predicate = R.where({
published: R.equals(true),
tags: R.where({
visibility: R.equals('myself'),
}),
});
// ==
const data = [
{title: 'title 1', published: false, pages: 30, tags: {name: 'work', id: 1, visibility: "everyone"}},
{title: 'title 2', published: false, pages: 25, tags: {name: 'home', id: 3, visibility: "myself"}},
{title: 'title 3', published: true, pages: 30, tags: {name: 'vacation', id: 5, visibility: "myself"}}
];
console.log(
R.filter(predicate, data),
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.js" integrity="sha256-buL0byPvI/XRDFscnSc/e0q+sLA65O9y+rbF+0O/4FE=" crossorigin="anonymous"></script>
添加回答
举报