【发布时间】:2018-10-12 19:47:46
【问题描述】:
这是我第一次尝试 Gatsby 和 Axios,以便从 API 获取一些 json。
基本上,我正在尝试从这个 json 文件中检索一些 json 数据:
{
"filters": {},
"competition": {
"id": 2019,
"area": {
"id": 2114,
"name": "Italy"
},
"name": "Serie A",
"code": "SA",
"plan": "TIER_ONE",
"lastUpdated": "2018-10-08T15:10:08Z"
},
"season": {
"id": 290,
"startDate": "2018-08-18",
"endDate": "2019-05-26",
"currentMatchday": 9,
"winner": null
},
"standings": [
{
"stage": "REGULAR_SEASON",
"type": "TOTAL",
"group": null,
"table": [
{
"position": 1,
"team": {
"id": 109,
"name": "Juventus FC",
"crestUrl": "http://upload.wikimedia.org/wikipedia/de/d/d2/Juventus_Turin.svg"
},
"playedGames": 8,
"won": 8,
"draw": 0,
"lost": 0,
"points": 24,
"goalsFor": 18,
"goalsAgainst": 5,
"goalDifference": 13
]
}
]
}
这是我用来映射数据的方法:
team.data.standings.map((team, i) => {
const standingsNode = {
id: `${i}`,
parent: `__SOURCE__`,
internal: {
type: `Season`,
},
children: [],
stage: team.stage,
type: team.type,
}
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(standingsNode))
.digest(`hex`);
standingsNode.internal.contentDigest = contentDigest;
createNode(standingsNode);
});
我的问题是,如何在我的代码中映射“排名”的“表”子项? 当我尝试在 GraphiQL 中查询时,我似乎无法深入到表数据,我只能从 json 数据中获取阶段和类型(见下图)
非常感谢任何帮助!
【问题讨论】:
标签: javascript json reactjs axios gatsby