【发布时间】:2021-05-01 06:13:14
【问题描述】:
我想使用语义 HTML 标签(而不是使用 div)来创建一个带有 react-window 的表格。
问题在于 List (FixedSizedList) 创建了两个包装器。 另一个称为 outerElementType,也是 FixedSizedList 的一个 prop,默认值为 div。这意味着我无法创建正确的表结构,并且所有 td 最终都在第一列中。看起来这两个都不能省略。
我该如何解决这个问题?
当前代码:
import { FixedSizeList as List } from "react-window";
...
return (
<table className="CargoListTable">
<CargoTableHead />
<List
height={600}
itemCount={cargoList.length}
itemSize={35}
width={900}
itemData={cargoList}
innerElementType="tbody"
>
{Row}
</List>
</table>
)
const Row: React.FC<RowProps> = ({ index, style, data }) => {
const cargo = data[index];
return (
<tr
style={style}
key={index}
>
<td>{cargo.registrationNumber}</td>
<td>{cargo.pol}</td>
<td>{cargo.pod}</td>
</tr>
);
};
【问题讨论】:
标签: reactjs react-window