reactjs - 用 SVG 线连接反应组件
问题描述
我的 api 提供了上层父元素的 id,所有级别都位于同一个 React 组件中(就像卡片一样)。
如何将不同级别的卡片与 SVG 线连接起来?
我以为我可以得到每张卡片的所有坐标,然后根据关系我可以创建起点和终点的线。但我不知道如何获取它们,在父组件中,我应该有任何 Card 组件的引用以便使用,getBoundingClientRect()
尽管我没有找到将 N 引用存储在功能组件中的方法。
我还关心如何给连接器提供脚踝曲线。我目前正在使用 d3 绘制线条。
当前代码:
<Row style={{ position: 'relative' }}>
<Col span={8}>
<strong>TOP LEVEL</strong>
<Divider />
{data.length ? data[0].map(item => <ProductCard item={item} key={item.product_offer_id} />) : []}
</Col>
<Col span={8}>
<strong>SUB LEVEL 1</strong>
<Divider />
{data.length ? data[1].map(item => <ProductCard item={item} key={item.product_offer_id} />) : []}
</Col>
<Col span={8}>
<strong>SUB LEVEL 2</strong>
<Divider />
{data.length ? data[2].map(item => <ProductCard item={item} key={item.product_offer_id} />) : []}
</Col>
<svg id="svg1" style={{ margin: '0 auto', display: 'block', position: 'absolute' }}></svg>
</Row>
解决方案
推荐阅读
- node.js - 使用 Node.js 和 MongoDB 限制返回的文档
- r - 要替换的项目数不是替换长度错误的倍数
- javascript - 使用 function-plot.js 绘制指数函数
- java - 在Java中将父类转换为子类
- c# - 是否可以在一定天数后删除特定的 blob?Azure Blob 存储
- php - Content-Encoding 标头通过转发代理消失
- c - 检查字符串在 C 中是否为给定格式
- javascript - 错误处理响应:TypeError: Cannot read property 'show' of undefined at chrome-extension
- javascript - React Hooks ref.current 在测试期间未定义
- mysql - 嵌套和取消嵌套