[英]How can I print using map an array of arrays with objects within array react?
I have functional component that takes an array of arrays with objects but I don't know how to access data in the return function of the render我有一个功能组件,它接受一个 arrays 数组和对象,但我不知道如何访问渲染返回的 function 中的数据
let dataItems = [
[
{
data1: "1234",
data2: "ABCD",
data3: "5678",
data4: "EFGH",
},
{
data1: "10203040",
data2: "A1B1C1D1",
data3: "50607080",
data4: "EFGH",
},
{
data1: "6789",
data2: "jklm",
data3: "1000",
data4: "EFGH",
},
{
data1: "128",
data2: "zwxy",
data3: "5",
data4: "lmno",
},
],
[
{
data1: "1234",
data2: "ABCD",
data3: "5678",
data4: "EFGH",
},
{
data1: "10203040",
data2: "A1B1C1D1",
data3: "50607080",
data4: "EFGH",
},
{
data1: "6789",
data2: "jklm",
data3: "1000",
data4: "EFGH",
},
{
data1: "128",
data2: "zwxy",
data3: "5",
data4: "lmno",
},
],
];
I tried to pass the data to another component to print the data but I don't know how to pass an unnamed array with the map function.我试图将数据传递给另一个组件以打印数据,但我不知道如何传递带有 map function 的未命名数组。
My code.我的代码。
dataItems.map((item, index) => {
return (
{ item.content.map((c, i) =>
<PrintComponent>
)
}
)
})
I will print a bi-dimensional matrix in chunks of 4 elements using bootstrap 4 tabs我将使用 bootstrap 4 选项卡打印 4 个元素块中的二维矩阵
Im trying to show the data like a bi-dimensional array like this我试图像这样显示像这样的二维数组的数据
row1![]() |
row2![]() |
row3![]() |
row4![]() |
---|---|---|---|
data01![]() |
data02![]() |
data03![]() |
data04![]() |
data05![]() |
data06![]() |
data07![]() |
data08![]() |
... ...
I solved with make the component within the maps.我解决了在地图中制作组件的问题。
using this lines使用这条线
dataItems.map((item) => {
return item.map((items) => { console.log("data1", items.data1)});
});
gives me the data several times, so I include some slice for only one time给了我几次数据,所以我只包含了一些切片一次
dataItems.slice(0, 1).map((item) => {
return item.map((items) => { console.log(items)});
});
For this you have to use multiple maps for data rending.为此,您必须使用多个地图进行数据渲染。
For Example:例如:
dataItems.map((item) => {
return item.map((items) => { console.log("data1", items.data1)});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.