我有一個帶有ng-repeat的引導模型。它顯示JSON數據。 現在我想單擊一個團隊(teamname)並將其顯示在console.log中。但是,我的問題是我不能得到teams.team(隊名)...AngularJS - 獲取JSON屬性並顯示它
你有任何想法如何處理這個?
app.js
app.controller('modalController', ['$scope', '$timeout', '$http', function ($scope, $timeout, $http) {
$scope.$on('modal', function (event, args) {
$http.get('../data/teams.json').then(function (response) {
var teams = response.data.teams;
var teamsArray = [];
for (var p in teams) {
var d = teams[p];
teamsArray.push(d);
}
$scope.teamSelected = function() {
console.log("Clicked" + teams.team)
};
$scope.teams = teamsArray;
});
})
}]);
modal.html
<div class="col-md-4 col-sm-6 col-xs-12" ng-repeat="team in teams | filter:team | limitTo: paginationLimit()" ng-click="teamSelected(teams.team)">
<div class="row pad-team-selection-view">
<button type="button" class="btn btn-default team-selection-view">
<img ng-src="{{ team.logo }}" width="18" height="18" class="img-logo">{{ team.team }}
</button>
</div>
</div>
teams.json
{
"teams": [
{
"id": "0",
"league": "1. Bundesliga",
"team": "FC Augsburg",
"country": "Deutschland",
"logo": "https://upload.wikimedia.org/wikipedia/de/b/b5/Logo_FC_Augsburg.svg"
},
檢查我的回答恰好爲你工作。 –
很抱歉,但對方的回答是更詳細:( – jglom
@WilliamHampshire如果在計算器上一個公認的答案對你那麼重要,我會給你:) – jglom