[英]Displaying the keys value from a JSON array in AngularJS
How do I get the league titles from the given JSON to show in [TITLE]? 如何从给定的JSON获取联赛冠军以显示在[TITLE]中? Everything else works just fine, but I would like for it to show up in league categories.
其他一切都很好,但是我希望它能出现在联赛类别中。
My HTML: 我的HTML:
<div ng-controller="LeaguesCtrl">
<div ng-repeat="league in leagues">
League: {{[TITLE]}}
<table>
<tr ng-repeat="match in league">
<td>{{match.home_team}}</td>
<td>-</td>
<td>{{match.away_team}}</td>
<td><a href="#">{{match.home_odds}}</a></td>
<td><a href="#">{{match.draw_odds}}</a></td>
<td><a href="#">{{match.away_odds}}</a></td>
</tr>
</table>
<br />
</div>
</div>
My JSON: 我的JSON:
{
"UEFA Champions League": [
{
"id": 152494,
"home_team": "APOEL Nicosia",
"home_short": "",
"away_team": "Paris SG",
"away_short": ""
},
{
"id": 152519,
"home_team": "Chelsea",
"home_short": "",
"away_team": "Maribor",
"away_short": ""
}
],
"Barclays Premier League": [
{
"id": 126938,
"home_team": "Arsenal",
"home_short": "",
"away_team": "Hull",
"away_short": ""
},
{
"id": 126942,
"home_team": "Manchester C",
"home_short": "Man C",
"away_team": "Tottenham",
"away_short": "Man C"
}
]
}
My AngularJS controller: 我的AngularJS控制器:
myApp("LeaguesCtrl", function($scope, $http) {
$http.get('http://api.odds24.com/best-odds?user=dev&leagues=SOCENGPRE,SOCINTCHL,SOCESPPRI').
success(function(data, status, headers, config) {
$scope.leagues = data;
});
});
You have to specify in the ng-repeate, so like this; 您必须在ng-repeate中指定,就像这样;
<div class="col-lg-12" ng-controller="LeaguesCtrl">
<div ng-repeat="(key, league) in leagues">
League: {{key}}
<table>
<tr ng-repeat="match in league">
<td style="padding: 0 5px">{{match.home_team}}</td>
<td style="padding: 0 5px">-</td>
<td style="padding: 0 5px">{{match.away_team}}</td>
<td style="padding: 0 5px; text-align: right"><a href="#">{{match.home_odds}}</a></td>
<td style="padding: 0 5px; text-align: right"><a href="#">{{match.draw_odds}}</a></td>
<td style="padding: 0 5px; text-align: right"><a href="#">{{match.away_odds}}</a></td>
</tr>
</table>
<br />
</div>
</div>
Then just use {{key}}
. 然后只需使用
{{key}}
。
You would just use the key/value option in the ng-repeat. 您只需要在ng-repeat中使用key / value选项即可。 So it would look something like this:
所以看起来像这样:
<div ng-repeat="name, detail in league">
You then just reference it by using {{name}}
. 然后,您只需使用
{{name}}
来引用它。
More info in the docs for ng-repeat page. ng-repeat页面上的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.