在使用 Angular 的 mat-table 时,有时可能会出现重复行的情况,这是由于数据源中存在相同的数据导致的。要解决这个问题,我们可以通过以下方法:
示例代码:
import { Component } from '@angular/core'; import * as _ from 'lodash';
@Component({
selector: 'app-table',
template:
})
export class TableComponent {
dataSource = [
{id: 1, name: 'John'},
{id: 2, name: 'John'},
{id: 3, name: 'Peter'}
];
displayedColumns = ['id', 'name'];
{{column}} {{row[column]}}
constructor() { this.dataSource = _.uniqBy(this.dataSource, 'id'); } }
示例代码:
import { Component } from '@angular/core';
@Component({
selector: 'app-table',
template:
})
export class TableComponent {
dataSource = [
{id: 1, name: 'John'},
{id: 2, name: 'John'},
{id: 3,
{{column}} {{row[column]}}