【发布时间】:2020-08-19 19:41:05
【问题描述】:
我正在尝试返回一个对象列表,以便稍后在 ag-grid 中显示。但是我最初试图映射但注意到它不是一个数组,它只包含在 {} 中,因此得到了 not a function 错误。任何提示或相关资源的链接都将不胜感激,因为我找不到任何对我有帮助的东西
api 返回 {"author":"j.k rowling", "title":"Harry Potter", "id":"1", "pages":"1000"}
useEffect(() => {
fetch(http://fakeapi.com/)
.then(res => res.json())
.then(json => json.map(res => {
return {
author: res.author,
title: res.title,
id: res.id,
pages: res.pages,
};
})
).then(res => setRowData(res));
}, []);
【问题讨论】:
-
你可以试试
Object.values(json).map -
一直在尝试,但没有成功
标签: node.js reactjs fetch use-effect