【发布时间】:2021-12-29 16:37:20
【问题描述】:
我正在尝试获取我在react-three-fiber 中创建的对象的id。我尝试使用document.getElementById,但没有成功。
这是我创建的对象:
const createFace = () => {
let face = [];
let size = props.cubeArr[0].length;
for (let row = 0; row < size; row++) {
let rowArr = [];
for (let col = 0; col < size; col++) {
let position = [col - 1, size - 2 - row, 0];
rowArr[col] = (
<Cell
key={`${props.side}-${row}-${col}`}
id={`${props.side}-${row}-${col}`}
position={position}
/>
);
}
face[row] = <group key={`${props.side}-${row}`}>{rowArr}</group>;
为简洁起见,我没有包含其余的three.js 代码,但基本上我为我的每个Cells 设置了一个id,我想根据他们的ID 访问这些3D Cells,所以我可以运行click 函数。
我发现了一个类似的问题here,但看不到如何翻译它以做出反应
【问题讨论】:
标签: javascript three.js react-three-fiber