【发布时间】:2021-09-10 07:20:21
【问题描述】:
我是一个初学者,目前,我正在尝试学习如何使表格的行可拖动和重新排列。我正在使用 react-beautiful-dnd 库。我能够使行可拖动,但我无法在拖放后保存行的状态。 对于这方面的任何帮助,我将不胜感激。
import { Component } from 'react';
import React from 'react';
import './App.css';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
class App extends Component
{
drawTable = () => {
return (
<div>
<DragDropContext>
<Droppable droppableId="Table">
{(provided) => (
<table {...provided.droppableProps} ref={provided.innerRef}>
<Draggable draggableId='1' index={1}>
{(provided) => (
<tr ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
)}
</Draggable>
<Draggable draggableId='2' index={2}>
{(provided) => (
<tr ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<td>2</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
)}
</Draggable>
<Draggable draggableId='3' index={3}>
{(provided) => (
<tr ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<td>3</td>
<td>Larry the Bird</td>
<td>@twitter</td>
</tr>
)}
</Draggable>
{provided.placeholder}
</table>
)}
</Droppable>
</DragDropContext>
</div>
);
}
render = () => {
return (
<div>
{this.drawTable()}
</div>
);
}
}
export default App;
【问题讨论】:
标签: reactjs react-beautiful-dnd