[英]Why typescript (tsx) doesn't return html when map is using twice?
I've made array with chunks using this method:我使用这种方法制作了带有块的数组:
const newArray: Array<Array<any>> = [];
for (let i = 0; i < codeData?.length; i++) {
if (i % 3 === 1) {
newArray.push([codeData[i - 1], codeData[i], codeData[i + 1]].filter(el => el !== undefined));
}
}
But when I try to map it twice It doesn't return HTML
, but when I set the value of the last map to the console it returns what I need:但是当我尝试 map 它两次它不会返回
HTML
,但是当我将最后一个 map 的值设置到控制台时,它会返回我需要的内容:
{newArray
?.slice(
page * rowsPerPage,
page * rowsPerPage + rowsPerPage
)
?.map((arr: any) => {
arr
.filter((element) => element !== undefined)
.map((row: any) => {
return (
<TableRow
role="checkbox"
key={row.id}
className={classes.row}
>
{row.id}
</TableRow>
);
});
})}
I guess it happened because typescript, as for as I know, has this dynamic - []
but when I'm using map twice it has - [[]]
.我想这是因为 typescript,据我所知,有这个动态 -
[]
但是当我使用 map 两次它有 - [[]]
。
Anybody can help me?任何人都可以帮助我吗?
map
return an array and if you nest them you will get nested arrays too. map
返回一个数组,如果你嵌套它们,你也会得到嵌套的 arrays。
If you change the first map
to flatMap
it will falten the results in to a single array.如果您将第一个
map
更改为flatMap
,它会将结果折叠成单个数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.