简体   繁体   English

我如何使用 map 打印一个 arrays 数组,数组中的对象反应?

[英]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排2 row3第三行 row4第4行
data01数据01 data02数据02 data03数据03 data04数据04
data05数据05 data06数据06 data07数据07 data08数据08

... ...

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.

相关问题 如何 map arrays 的 arrays 数组与反应中的对象 - How to map an array of arrays of arrays with objects in react 获取对象数组后,如何使用 if 语句有条件地映射多个数组? (反应) - How can I conditionally map multiple arrays with if statements after fetching an array of objects? (React) 将AngularJS与嵌套在数组中的数组中的JSON对象一起使用,如何将数据获取到html中? - Using AngularJS with JSON objects in arrays nested within an array, how can I get the data into the html? 如何使用.map从对象数组创建数组数组? - How to create an array of arrays, from an array of objects using .map? 通过对象数组和 arrays 反应 map - React map through an array of objects and arrays 在 React 中,如何使用“map”将对象数组转换为新的对象数组? - In React, how can I use “map” to transform an array of objects into a new array of objects? 如何在 React 中彻底映射包含其他对象和数组的整个数组? - How do I map thorough the entire array which contains other objects and arrays as well in React? 如何映射对象中具有数组的对象数组 - How to map an Array of objects, that have arrays in the objects 如何使用 React map 对象数组的对象数组 - how to map an array of objects of array of objects with React 如何将数组与打字稿中的对象映射 - How can I map array with objects in typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM