1 回答

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
我認(rèn)為您只是插入dragableId,您可以使用該函數(shù)找到整個(gè)對(duì)象并插入整個(gè)對(duì)象newRowOrder.splice(destination.index, 0, **draggableId**);Array.find
onDragEnd = (result) => {
const { destination, source, draggableId, type } = result;
if (!destination) {
return;
}
if (
destination.draggableId === source.droppableId &&
destination.index === source.index
) {
return;
}
if (type === "row") {
const draggableRow = this.state.currentRows.find(row => row.id === draggableId);
const newRowOrder = Array.from(this.state.currentRows);
newRowOrder.splice(source.index, 1);
newRowOrder.splice(destination.index, 0, draggableRow);
const newState = {
...this.state,
currentRows: newRowOrder,
};
this.setState(newState);
}
}
添加回答
舉報(bào)