亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

映射數組并返回 API 結果

映射數組并返回 API 結果

慕娘9325324 2021-06-09 13:35:21
嘗試使用簡單的代碼映射數組,并針對每個結果在 API 中搜索該結果并吐出從 API 檢索到的數據。import React from 'react';const App = () => {  let artistData = require('./mass-artists.json')  artistData.map(    (theArtist) => {        fetch(`[url]https://api.scryfall.com/cards/search?q=a:[/url]"${theArtist}"`)            .then((response) => {              return response.json();            })            .then((myJson) => {              console.log(JSON.stringify(myJson)); //returns the JSON data, so I know it's working              console.log(myJson.data[0].name); //returns the first card name            })    }  )  return(<span>This is here so React doesn't yell at me about no return statement.</span>)}export default App;JSON 文件只是 Magic 藝術家姓名的列表。該地圖映射藝術家列表并在 API 上搜索他們。我想做我對地圖所做的通常的事情,即在前端顯示一些東西。但是我無法正常工作。我可以將內容記錄到控制臺或執行任何 Javascript 功能,例如設置某些內容的 innerHTML,但是我將在哪里/如何放置 return 語句以在例如 span 標簽中顯示結果?甚至如“你好!”。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號