我想根据gameId
返回所有字段我尝试了下面的代码但是当我console.log(vm.game.team1)
时它返回undefined
而console.log(vm.game)
只返回gameId。
如何访问游戏数据中的所有属性。
"games": [
{
"id": 1016,
"location": "North Laurel Comm. Center Ct. 5",
"locationUrl": "url",
"locationId": 1003,
"team1": "Patapsco",
"team1Id": 45,
"team2": "Sharks-6th (Green)",
"team2Id": 1,
"team1Score": "20",
"team2Score": "38",
"time": "2013-12-06T18:00:00"
}
]
我的应用:
(function () {
'use strict';
angular.module('eliteApp').controller('GameCtrl', ['$stateParams','eliteApi', GameCtrl]);
var data = eliteApi.getLeagueData();
vm.game = _.find(data.games, {id: gameId});
console.log(vm.game); // returns gameId
console.log(vm.game.team1); // returns undefine
})();