在反应中获取内部地图

Fetch inside map in react

我正在尝试通过其 campaignId 获取每个活动统计信息。 campaignId 从第一个 api 调用中提取,然后在迭代时我将该 id 传递给下一个 api 调用以获取每个活动统计信息。第一个 api 调用给出了正确的结果,但是在从第二个 api 调用迭代和获取它时它抛出

的错误

Unhandled Rejection (TypeError): ids.map is not a function

export const loadStats = async () => {
    const ids = await (await fetch('https://api.truepush.com/api/v1/listCampaign/1', {
        method: "GET",
        headers: {
            Authorization: `${TOKEN}`,
            "Content-Type": "application/json"
        }
    })).json()

    const data = Promise.all(
        ids.map(async (i) => await (await fetch(`https://api.truepush.com/api/v1/campaignStats/${i.data.campaignId}`, {
            method: "GET",
            headers: {
                Authorization:`${TOKEN}`,
                "Content-Type": "application/json"
            }
        })).json())
    )
    return data
};

我在迭代时期待所有这些统计数据:

https://i.stack.imgur.com/8kjwy.png

https://i.stack.imgur.com/VJni7.png listCampaign/1 的结果)

试试这个:

export const loadStats = async () => {
    const ids = await (await fetch('https://api.truepush.com/api/v1/listCampaign/1', {
        method: "GET",
        headers: {
            Authorization: `${TOKEN}`,
            "Content-Type": "application/json"
        }
    })).json()

    const data = Promise.all(
        ids.data.map(async (i) => await (await fetch(`https://api.truepush.com/api/v1/campaignStats/${i.campaignId}`, {
            method: "GET",
            headers: {
                Authorization:`${TOKEN}`,
                "Content-Type": "application/json"
            }
        })).json())
    )
    return data
};