You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目用react-beautiful-dnd报错:无法找到ID为x的可拖拽元素

React-beautiful-dnd拖拽报错:Unable to find draggable with id x

基于示例代码修改后,仅调整了每个可拖拽行的内容,尝试拖拽表格行元素时触发报错:Unable to find draggable with id x。

数据

questions数据结构如下:

[
    {
      "id": 499,
      "type": "text",
      "text": "T1"
    },
    {
      "id": 500,
      "type": "text",
      "text": "How are you doing?"
    }
]

UI截图

表格UI截图

代码

<TableContainer component={Paper}>
    <Table sx={{ minWidth: 650 }} aria-label="simple table">
        <TableHead>
        <TableRow>
            <TableCell align="left"><strong>Title</strong></TableCell>
            <TableCell align="left"><strong>Question Type</strong></TableCell>
            <TableCell align="left"><strong>Recommend Answer Duration</strong></TableCell>
            <TableCell align="left"><strong>Actions</strong></TableCell>
        </TableRow>
        </TableHead>
        <DragDropContext onDragEnd={onDragEnd}>
            <Droppable droppableId="droppable">
            {(provided, snapshot) => (
                <tbody
                {...provided.droppableProps}
                ref={provided.innerRef}
                >
                <TableRow>
                    <TableCell component="th" scope="row">
                        <button className="questions-add-question-button">+ Add Question</button>
                    </TableCell>
                    <TableCell align="left">-</TableCell>
                    <TableCell align="left">-</TableCell>
                    <TableCell align="left"></TableCell>
                </TableRow>
                {questions.map((question:any, index) => (
                    <Draggable key={question.id.toString()} draggableId={question.id.toString()} index={index}>
                    {(provided, snapshot) => (
                        <TableRow
                            ref={provided.innerRef}
                            {...provided.draggableProps}
                            {...provided.dragHandleProps}>
                            <TableCell component="th" scope="row">
                                {question.text}
                            </TableCell>
                            <TableCell align="left">{question.type}</TableCell>
                            <TableCell align="left">{question.recommend_answer_duration} Second(s)</TableCell>
                            <TableCell align="left">                                        
                                <DropDown
                                    text="Actions"
                                    buttons={
                                        <>
                                            <button>Delete</button>
                                        </>
                                    }
                                />
                            </TableCell>
                        </TableRow>
                    )}
                    </Draggable>
                ))}
                {provided.placeholder}
                </tbody>
            )}
            </Droppable>
        </DragDropContext>
    </Table>
</TableContainer>

内容的提问来源于stack exchange,提问作者X3R0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 03:05:28