我正在使用一个库在 react-pdf 中创建表。我想用api数据填充它。有没有办法在数据内部进行迭代{}并使用来自 api.xml 的数据创建各种对象。而不是 sth like
data={[{firstName: "John", lastName: "Smith",country: "Australia"}]},
data={[{firstName: "Josh", lastName: "Pattison",country: "USA"}]}
有
data={[{firstName: "John", lastName: "Smith",country: "Australia"}],
[{firstName: "Josh", lastName: "Pattison",country: "USA"}]
}
代码
{Data.attributes.map((details) => (
<TableBody data={[
{firstName: details.attributes.filter(
(x) => x.displayName === "first name"
)[0].value,
lastName: details.attributes.filter(
(x) => x.displayName === "last name"
)[0].value,
country: details.attributes.filter(
(x) => x.displayName === "country"
)[0].value},
]}>
</TableBody>
...