首页 > 解决方案 > 在Angular中对表格行进行排序

问题描述

所以我需要按歌曲的持续时间对我的桌子进行排序,我有点迷茫,我正在学习 Angular,所以我会感谢你的帮助。我会发布一些我的代码。

我需要的是订购包含元素的预览列。

  <div>
    <table class="table">
      <thead>
        <tr>
          <th class="styled-tableheader">
                  Preview
        </th>
          <th class="styled-tableheader">Like it!</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let track of albumTracks">
          <td>
            <iframe
            [src]="track.uri | domsanitizer"
            width="320"
            height="90"
            frameborder="0"
            allowtransparency="true"
            allow="encrypted-media"
          ></iframe>
          </td>
          <td>
            <button (click)="addToPlaylist( track )" type="button" class="myButton">Add to playlist!</button>
          </td>
        </tr>
      </tbody>
    </table>
  </div>

这是组件。从这里我得到数据,我需要来自“albumTracks”的属性是“duration_ms”

getAlbumTracks( id:string ){
  debugger;
  this.spotify.getAlbumsTracks( id ).subscribe( albumTracks => {
    this.albumTracks=albumTracks;
    console.log(albumTracks);
  } )
}

如果您能提供帮助,我将不胜感激。非常感谢。

标签: angularsortingrows

解决方案


推荐阅读