我有一个cdk表来显示数据,但是我有一些重复的数据,并且 这样的数据源
[
{customerID:"56789", name: "foo", mobile: "123456"},
{customerID:"56789", name: "foo", mobile: "123456"},
{customerID:"12345", name: "foo", mobile: "123456"},
{customerID:"12345", name: "foo", mobile: "123456"},
{customerID:"45678", name: "foo", mobile: "123456"}
]
现在,我想隐藏具有相同customerID的列。因此,列表中仅显示3条记录,而不是显示5条记录。 有什么条件可以申请mdTable或md-cell来实现吗? 谢谢您的帮助。
答案 0 :(得分:1)
您可以制作一个管道来过滤数据,例如:
@Pipe({
name: 'filterId',
pure: false
})
export class FilterValue implements PipeTransform {
transform(items: any[]): any {
const uniqueArr = [];
const ids = items.map((value) => value.customerID);
items.map((value, index) => {
if(ids.indexOf(value.customerID) !== index) {
// duplicate value, delete or do whatever you want to
delete value.customerID
uniqueArr.push(value)
} else {
uniqueArr.push(value)
}
})
return uniqueArr;
}
}
并在您看来:
<div *ngFor="let item of ArrayVariable | filterId">
<div *ngIf="item.customerID">