angular - Angular Material Table 更改特定行内容
问题描述
我有带有材料表的 Angular 7:
<mat-table #table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="Extension">
<mat-header-cell *matHeaderCellDef (click)="sortData('agentExtn')" class="pointer" [ngClass]="getSortClass('agentExtn')" id="ExtnHeader" >
{{ ExtnHeader | translate }} <div></div >
</mat-header-cell> <mat-cell *matCellDef="let element" class="ExtnCol"> {{ element.Extn }} </mat-cell>
</ng-container>
<ng-container matColumnDef="Play">
<mat-header-cell *matHeaderCellDef>{{ 'MAIN.PLAY' | translate }}</mat-header-cell>
<mat-cell *matCellDef="let element">
<button id="play" class="float-right icon-link" mat-icon-button matTooltip="{{ 'MAIN.PLAY' | translate }}" (click)=" $event.stopPropagation(); playRecord(element.recordId)" >
<i class="fa fa-play" aria-hidden="true"></i>
</button>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns" [ngClass]="{ 'highlight-row': selectedRow == row.MediaRecord.$.recordId, pointer: true }" (click)="showRecordDetailsDialog(row)">
</mat-row>
</mat-table>
所以行看起来类似于以下内容:
单击播放图标时,音频元素会显示在屏幕的其他位置。
现在,我希望将该特定行的播放图标替换为暂停图标。此外,如果用户单击另一行的播放图标,则带有暂停图标的前一行应替换为播放图标。
我怎样才能做到这一点?如何获取对特定行的引用并替换那些特定图标?
解决方案
将另一个isPlaying[]
布尔数组初始化为 false(或向现有的数组添加新列),在其中保存每一行的状态,并根据该数组更改图标。制作另一个数组(或向现有数组添加新列一)保存每一行的状态,并根据该数组更改图标。
<mat-cell *matCellDef="let element; let i = index">
<button id="play" class="float-right icon-link" mat-icon-button matTooltip="{{ 'MAIN.PLAY' | translate }}" (click)=" $event.stopPropagation(); playRecord(element.recordId, i)" >
<i *ngIf="isPlaying[i]=false" class="fa fa-play" aria-hidden="true"></i>
<i *ngIf="isPlaying[i]=true" class="fa fa-pause" aria-hidden="true"></i>
</button>
</mat-cell>
您playRecord
应该根据 播放/暂停isPlaying[i]
,这就是我i
作为参数传递的原因。
推荐阅读
- xml - 是否有将 OO 对象与 XML 相互转换的标准?
- makefile - make 命令未检测到 windows10 中的 make 文件
- git - 有没有办法让 Git 将特定文件从不同的分支拉到我的分支?
- c# - 我一直试图让我的 Unity 2D 播放器移动,但看起来我在脚本中犯了一个我找不到的错误
- python - 使用 SQLite3 从 for 循环添加列
- python - 无法使用 Anaconda 3.4.8 安装软件包
- php - 数据未正确存储在数据库中,laravel,php
- python - Pandas dataframe.loc:“与行轴长度相同的布尔列表”是什么意思?
- autodesk-forge - 使用 Autodesk 对象 ARX 或可执行文件读取绘图文件 (CTB/STB)
- html - 我从官方引导网站 v4.0 复制了一个导航栏代码,代码相同但输出不同,为什么会这样?