以下是根據您的要求顯示結果的一種方法。看看這個plunker作爲一個工作的例子。
基本上從你在數據庫中獲得數據的方式來看,在比賽中做內部重複練習,並在內部對運動員進行重複練習。然後爲每個運動員看看他們是否有該事件的獎項。
希望這有助於和給你一個起點,您的解決方案
HTML:
<body ng-controller="MainCtrl">
<div class="panel panel-default" ng-repeat="event in competitions">
<div class="panel-heading"><strong>{{event.name}}</strong></div>
<div class="panel-body">
<strong>Atheletes:</strong>
<span ng-repeat="athelete in event.athletes">{{athelete.name}}
<span class="text-info">{{GetPrize(event.prizes,athelete)}}</span>
</span>
</div>
</div>
</body>
控制器:
app.controller('MainCtrl', function($scope) {
$scope.competitions = [{
"id": 1,
"name":"City Marathon",
"athletes":[{"id":1, "name": "Ashley"},{"id":2, "name": "John"},{"id":3, "name": "Kim"},{"id":4, "name": "Nick"}],
"prizes": [{"id":1,"comp_id":1,"prize_num":1,"athlete_id":3},{"id":2,"comp_id":1,"prize_num":2,"athlete_id":1}]
},
{
"id": 1,
"name":"5K Marathon",
"athletes":[{"id":1, "name": "Ashley"},{"id":2, "name": "John"},{"id":3, "name": "Kim"},{"id":4, "name": "Nick"}],
"prizes": [{"id":1,"comp_id":1,"prize_num":1,"athlete_id":4},{"id":2,"comp_id":1,"prize_num":2,"athlete_id":2}]
}
];
$scope.GetPrize = function(prizes,athelete){
var prize_info ="";
for(var i=0;i<prizes.length;i++){
if(prizes[i].athlete_id == athelete.id){
prize_info = "("+prizes[i].prize_num+" Prize)";
}
}
return prize_info;
}
})
你需要去創建自定義過濾器 –
您可以加入什麼你已經試過 –
許多方法可以做到這一點,都需要使用js進行某種映射或數據過濾。你的嘗試有什麼問題? – charlietfl