私のアプリケーションには、モーダルウィンドウに表示して循環させる独自の属性を持つ「プレーヤー」のセットがあります。 UIは次のようになります。anglejsの配列にxオブジェクトを表示
<!-- Score Round Modal -->
<div class="modal fade" id="myScoreModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" ng-repeat="player in players">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Score for {{player.data}}</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal" ng-click="cancelRound()">Cancel</button>
<button type="button" class="btn btn-warning" ng-click="previousPlayer()">Previous</button>
<button type="button" class="btn btn-default" ng-click="nextPlayer()">Next Player</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="calculateRound()">Finish</button>
</div>
</div>
</div>
</div>
ここで、プレイヤー(および後でいくつかの属性)を表示したい場合は、表示するファーストネームを取得できます。しかし、私は関数previousPlayer()
とnextPlayer()
を使って循環したいと思います。 js
セクションでは、私が増加変数と減少がそうのようなcurrentPlayer
と呼ばれています:
$scope.nextPlayer = function() {
// Cycles to next player cards within the round
$scope.currentPlayer++;
console.log($scope.currentPlayer);
};
$scope.previousPlayer = function() {
// Cycle to previous player cards within the round
$scope.currentPlayer--;
console.log($scope.currentPlayer);
};
目標はただ表示するだけでなく、player
モデルを修正しないことができるようになります。
' ng-repeat = "player in player" '$ ng-repeat ="プレイヤーのトラックを$ index "$"で置き換えると、 'ng-if ="($ indexの条件)を実行することができます。 $ index = 'players'配列で使用されるインデックス。別の方法は、players_in_cycleという別の配列を作成し、その中の場所を入れ替えることです。 –
だから 'ng-if ="(currentPlayer = $ index) "'は表現のように感じますが、どこに置くのですか? – Macness
期待される動作は何ですか?表示されているデータを1つのモーダルとトグルするだけのようです。どのようなモーダルライブラリを使用していますか? – charlietfl