0
我在查詢airtable的一些數據,這些數據基本上是書籍和相關作者的數據庫。每本書籍都有一個authorId
字段,我必須單獨查詢才能獲取相關的作者數據。我如何異步同時等待多個承諾? [語法錯誤:await是保留字]
這裏是我得到的所有的書第一:
let books = await axios.get("https://api.airtable.com/v0/appGI25cdNsGR2Igq/Books?&view=Main%20View")
let authorIds = books.data.records.map((book) => book.fields.Author[0])
這工作,我得到這些作者的ID:
[ 'recNLaQrmpQzfkOZ1',
'recmDfVxRp01x85F9',
'recKQqdJ9a2pHnF2z',
'recKMiDhdCUxfdPSY',
'rec67WoUDFjFMrw44' ]
現在我想這個數據發送到這樣一個getAuthors
功能:
const getAuthors = async (authorIds) => {
authorIds.map(id => await Promise.all([
return axios.get(`https://api.airtable.com/v0/appGI25cdNsGR2Igq/Authors/${id}`
])))
}
這個函數應該讓我知道我的相關作者數據,但是我得到了一個呃ROR:
Syntax Error: await is a reserved word
...在這條線:authorIds.map(id => await Promise.all([...
我在做什麼錯的,是有辦法解決這一問題?
我的巴貝爾設置工作正常,我使用了預先配置用於翻譯等的next.js。此外,第一次請求書的作品很好,這意味着異步不是問題 –
更新了我得到錯誤的行:'authorIds .map(id =>等待Promise.all([' –
爲什麼你需要async/await + promises?這是兩種不同的模式來管理異步代碼。 – Booster2ooo