相对于用户在玩家数组中的位置按顺序显示玩家

Display players in order relative to a user's position in players array

我正在使用 AngularJS 制作纸牌游戏,我想按照相对于用户位置的游戏顺序显示玩家。用户名片始终位于屏幕底部的单独 div 中。为了保持顺时针方向的播放顺序,它应该首先显示下一个玩家,然后是下一个,然后是下一个,等等。我目前正在使用 ng-repeat 指令,但这总是将玩家 1 放在第一位。

//- The Players 
  .row.center-block
    .col-md-2(ng-if='player.id != p.id ', ng-repeat='p in game.players')
      .row
        .col-md-12
          | {{p.name}}
          span.glyphicon.glyphicon-heart(ng-repeat='a in range(p.lives) track by $index')
        .col-md-12
          .card.col-md-1(ng-repeat='card in p.hand track by $index')
            | {{$index}}

如何从播放器对象开始循环播放播放器数组?我的理论是迭代两次,首先是数组中 ng-if='player.id != p.id ' 之后的每个人,然后是之前的每个人。是否也可以从特定索引开始?

使用 filter 对 ng-repeat 中的列表进行排序

移除

ng-if='player.id != p.id '

添加

ng-repeat='p in game.players | orderBy: position'

我想按顺序执行此操作,但事实证明在 javascript 中执行逻辑更容易。在我在玩家数组中找到用户位置 (x) 的位置处理游戏数据的部分中,我把这个:

$scope.otherPlayers = $scope.game.players.slice(x).concat( $scope.game.players.slice(0,x) );

而在我的 html 中,我将其更改为

.col-md-2(ng-if='player.id != p.id ', ng-repeat='p in otherPlayers')

而且效果非常好。