我正在使用 AngularJS 制作纸牌游戏,我想按照相对于用户位置的游戏顺序显示玩家。用户的卡片始终位于屏幕底部的单独分区中。为了保持顺时针方向的播放顺序,它应该首先显示下一个玩家,然后是下一个,然后是下一个,等等。我目前正在使用 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 - 按相对于玩家在玩家数组中的位置的顺序显示玩家,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27773457/