Code javascript pour récupérer un tableau dans un tableau en retour JSON

Nouveau WRInaute
bonjour ,

voilà je n'ai pas trouvé comment spécifier la lecture d'un tableau dans un tableau (hormis faire une boucle), mais je souhaitais faire un mapping direct
j'ai un ordre ajax / JSON qui me donne un retour que je map via
Code:
var SEASON = {
                    "td": {
                        "season<-results[0].seasonList": {
                                       "span.SeasonID": function(arg) {
                                                      // log le résultat de SeasonId  
                                        console.log ('season.seasonId:' + season[0].seasonId);

j'ai en retour dans le log couldn't display seasonId of undefined

les data en retours de mon call ajax sont
Code:
....
"results": [
        {
            "title": "Game of Thrones",
            "originalTitle": "Game of Thrones",
            "year": 2011,
            "watched": false,
            "artwork": {
                "POSTER": [
                    {
                        "id": 1,
                        "source": "SERIES",
                        "artworkId": 1162,
                        "locatedId": 6420,
                        "generatedId": 4005,
                        "artworkType": "POSTER",
                        "filename": "g/ga/Game Of Thrones_0000.series.poster.21285489.default.jpg"
                    },
                    {
                        "id": 1,
                        "source": "SERIES",
                        "artworkId": 1162,
                        "locatedId": 6418,
                        "generatedId": 4003,
                        "artworkType": "POSTER",
                        "filename": "g/ga/Game Of Thrones_0000.series.poster.21285491.default.jpg"
                    },
                    {
                        "id": 1,
                        "source": "SERIES",
                        "artworkId": 1162,
                        "locatedId": 6416,
                        "generatedId": 4006,
                        "artworkType": "POSTER",
                        "filename": "g/ga/Game Of Thrones_0000.series.poster.21262775.default.jpg"
                    },
                    {
                        "id": 1,
                        "source": "SERIES",
                        "artworkId": 1162,
                        "locatedId": 6419,
                        "generatedId": 4004,
                        "artworkType": "POSTER",
                        "filename": "g/ga/Game Of Thrones_0000.series.poster.21285490.default.jpg"
                    },
                    {
                        "id": 1,
                        "source": "SERIES",
                        "artworkId": 1162,
                        "locatedId": 6417,
                        "generatedId": 4002,
                        "artworkType": "POSTER",
                        "filename": "g/ga/Game Of Thrones_0000.series.poster.21285492.default.jpg"
                    }
                ]
            },
            "seriesId": 1,
            "seasonList": [
                {
                    "title": "Game of Thrones",
                    "originalTitle": "Game of Thrones",
                    "year": 2011,
                    "watched": false,
                    "artwork": {
                        "POSTER": [
                            {
                                "id": 10,
                                "source": "SEASON",
                                "artworkId": 20940,
                                "locatedId": 21443,
                                "generatedId": 18845,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_001.season.poster.121361-1-4.default.jpg"
                            }
                        ]
                    },
                    "seriesId": 1,
                    "seasonId": 10,
                    "season": 1,
                    "artworkCount": 1
                },
                {
                    "title": "Game of Thrones",
                    "originalTitle": "Game of Thrones",
                    "year": 2012,
                    "watched": false,
                    "artwork": {
                        "POSTER": [
                            {
                                "id": 11,
                                "source": "SEASON",
                                "artworkId": 21026,
                                "locatedId": 21521,
                                "generatedId": 18896,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_002.season.poster.121361-2-15.default.jpg"
                            }
                        ]
                    },
                    "seriesId": 1,
                    "seasonId": 11,
                    "season": 2,
                    "artworkCount": 1
                },
                {
                    "title": "Game of Thrones",
                    "originalTitle": "Game of Thrones",
                    "year": 2013,
                    "watched": false,
                    "artwork": {
                        "POSTER": [
                            {
                                "id": 34,
                                "source": "SEASON",
                                "artworkId": 21168,
                                "locatedId": 21573,
                                "generatedId": 18976,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_003.season.poster.121361-3-19.default.jpg"
                            }
                        ]
                    },
                    "seriesId": 1,
                    "seasonId": 34,
                    "season": 3,
                    "artworkCount": 1
                },
                {
                    "title": "Game of Thrones",
                    "originalTitle": "Game of Thrones",
                    "year": 2014,
                    "watched": false,
                    "artwork": {
                        "POSTER": [
                            {
                                "id": 33,
                                "source": "SEASON",
                                "artworkId": 21140,
                                "locatedId": 21552,
                                "generatedId": 18946,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_004.season.poster.121361-4-13.default.jpg"
                            }
                        ]
                    },
                    "seriesId": 1,
                    "seasonId": 33,
                    "season": 4,
                    "artworkCount": 1
                },
                {
                    "title": "Game of Thrones",
                    "originalTitle": "Game of Thrones",
                    "year": 2015,
                    "watched": false,
                    "artwork": {
                        "POSTER": [
                            {
                                "id": 1,
                                "source": "SEASON",
                                "artworkId": 1165,
                                "locatedId": 6401,
                                "generatedId": 4001,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_005.season.poster.121361-5-5.default.jpg"
                            }
                        ]
                    },
                    "seriesId": 1,
                    "seasonId": 1,
                    "season": 5,
                    "artworkCount": 1
                },
                {
                    "title": "Game of Thrones",
                    "originalTitle": "Game of Thrones",
                    "year": 2016,
                    "watched": true,
                    "artwork": {
                        "POSTER": [
                            {
                                "id": 35,
                                "source": "SEASON",
                                "artworkId": 21199,
                                "locatedId": 21608,
                                "generatedId": 18998,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_006.season.poster.121361-53.default.jpg"
                            },
                            {
                                "id": 35,
                                "source": "SEASON",
                                "artworkId": 21199,
                                "locatedId": 23750,
                                "generatedId": 21142,
                                "artworkType": "POSTER",
                                "filename": "g/ga/Game Of Thrones_0000_006.season.poster.121361-49.default.jpg"
                            }
                        ]
                    },
                    "seriesId": 1,
                    "seasonId": 35,
                    "season": 6,
                    "artworkCount": 2
                }
            ],
            "artworkCount": 5
        }
    ]
}
 
Nouveau WRInaute
je vais essayer d'être plus clair ,

j'ai un tableau results [] et dans ce tableau en niveau 1 j'ai un autre tableau seasonList[]
ceci est dans le code retour ajax de mon post (liste brut des data retournées)


je cherche à mapper directement le second tableau via une affectation dynamique dans la variable qui va être remplie
SEASON
par l'instruction "season<-results[0].seasonList"

mais lorsque je fais cela la variable season n'a pas de contenu (lorsque je cherche la valeur de season[0].seasonId le log me retourne 'undefined')

ma question est : ou est mon errur de syntaxe

Remarque :
si je mappe avec "season<-results":
alors la valeur season[0].seasonList[0].seasonId est correcte
 
Discussions similaires
Haut