https://codepen.io/leongaban/pen/EgvBpx
据我了解,我只是将我的comboTags数组传入。数据总是存在于Ramda语句的右侧。
我希望flatTags
包含tag1
和tag2
const comboTags = [
{
tags: [
{
name: 'tag1'
}
],
person: {
name: 'Jerry'
}
},
{
tags: [
{
name: 'tag2'
}
],
person: {
name: 'Laura'
}
}
];
const flattenTags = container => R.flatten(R.map(R.prop('tags')));
let flatTags = flattenTags(comboTags);
console.log('flatTags',flatTags);
答案 0 :(得分:1)
我相信您正在寻找pluck
并注意使用compose
或者使用pipe
!这允许无点函数:Try It Out
const comboTags = [
{
tags: [
{
name: 'tag1'
}
],
person: {
name: 'Jerry'
}
},
{
tags: [
{
name: 'tag2'
}
],
person: {
name: 'Laura'
}
}
];
const getTagNames = R.compose(R.pluck('name'), R.flatten, R.pluck('tags'))
getTagNames(comboTags) // ['tag1', 'tag2']