我正在用两个表渲染 json,每个表都有 x y 坐标。我需要根据这些坐标来绘制这些表格。
"tables": [
{ "tableName": "One",
"coordinates": {
"x": "100",
"y": "100"
},
"columns": [{},{}]
},
{"tableName": "Two",
"coordinates": {
"x": "200",
"y": "200"
},
"columns": [{},{}]
}]
使用 map 方法遍历表后,我将数据“打包”到 . 我正在尝试将 style={{}} 分配给具有这些坐标的容器,但它们是相互叠加的。
export const Table = ({table}) => {
const {tableName, coordinates} = table;
return (
<div style={{position: "absolute", left: coordinates.x, top: coordinates.y}}>
<p>{tableName}</p>
<div>{table.columns.map((el) => (
<div>{columnName}</div>))}
</div>
</div>
);
};
在我的情况下如何安排表格的正确坐标?
当样式通过 React 数字设置时,如果它们意味着像素应该是数字,而不是字符串,或者包含后缀
px
。在此示例中,我使用了两个选项: