【发布时间】:2019-09-03 01:58:44
【问题描述】:
我想用“uniqBy”过滤我的输入数据。我是打字稿的新手,不知道如何实现它。我知道我必须遍历每个子列表并为每个元素(data1,data2)制作 uniqby。这是我的输入数据如下:
const data = [
{
data1: [
{
id: "1",
label: "ONE",
anotherId: "3",
mygroupId: 1,
group: "Group_One",
},
{
id: "2",
label: "ONE",
anotherId: "33",
mygroupId: 1,
group: "Group_One",
},
{
id: "3",
label: "TWO",
anotherId: "11",
mygroupId: 1,
group: "Group_One",
},
]
},
data2: [
{
id: "4",
label: "ONE",
anotherId: "3",
mygroupId: 1,
group: "Group_One",
},
{
id: "5",
label: "TWO",
anotherId: "33",
mygroupId: 1,
group: "Group_One",
}
]
]
我想过滤我的数据,以便在每个列表 data1 和 data2 中只有基于这些组中每个项目的“标签”的唯一信息。
我想要类似的东西:
...
map(data => {
const grouped = groupBy(item => item.group, data);
const uniq = uniqBy( ... );
return uniq;
})
...
const uniqByLabel = [
{
data1: [
{
id: "1",
label: "ONE",
anotherId: "3",
mygroupId: 1,
group: "Group_One",
},
{
id: "3",
label: "TWO",
anotherId: "11",
mygroupId: 1,
group: "Group_One",
},
]
},
data2: [
{
id: "4",
label: "ONE",
anotherId: "3",
mygroupId: 1,
group: "Group_Two",
},
{
id: "5",
label: "TWO",
anotherId: "33",
mygroupId: 1,
group: "Group_Two",
}
]
]
【问题讨论】:
标签: angular typescript filter key-value