gpt4 book ai didi

javascript - 在angularjs中调用json数组

转载 作者:行者123 更新时间:2023-12-02 13:49:24 25 4
gpt4 key购买 nike

我有一个 json 数组

[{
"id": "21390238becde1290",
"chelsea": {
"homeTeam": "chelsea",
"sortName": "ches",
"awayTeam": "Maribor",
"awayShort": ""
},
"barclays": {
"id": "21390238becde1290",
"homeTeam": "barclays",
"sortName": "barc",
"awayTeam": "Hull",
"awayShort": ""
}
}]

Controller :

footBallApp.controller('TeamInfoEdit',
function ($rootScope, $scope, $state, $translate, carwashService) {

$rootScope.washTypes;

$scope.onViewLoaded = function () {
matchService.getTeamTypes($scope.TypeSelected);
}

$scope.TypeSelected = function (response) {
debugger;
if (response) {
$rootScope.teamAvailable = response;
$scope.localizedTeamName = getLocalizedCollection($scope.teamAvailable);
}
}

// Editing the Team Details.

$scope.editTeamDetails = function (key) {
console.log(key._id);

$rootScope.selectTeam =[];
for(var i=0; i<$scope.teamAvailable.length;i++){
if($scope.teamAvailable[i]._id== key._id)
{
console.log($scope.teamAvailable[i]);
$scope.selectTeam.push($scope.teamAvailable[i]);
debugger;

我已将该数组分配给 $scope.selectTeam。当我尝试调用 $scope.selectTeam.chelsea 时。我在控制台中将其显示为 Undefined 。在调用 json 时,我出错了,但找不到它,那么如何正确调用数组。因此寻求这方面的帮助。

最佳答案

我不知道你的数组是什么样子,但尝试调用:

$scope.selectTeam[0].chelsea

关于javascript - 在angularjs中调用json数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com