3

我想将一个元素从另一个元素移到另一个元素DragDropContext

我有一个://sidebar.js

<DragDropContext onDragEnd={() => console.log('sidebar end drag')}>

    <Droppable droppableId="sidebar">
       {provided => 
        <Draggable 
           ref={provided.innerRef} 
           {...provided.draggableProps} 
           {...other props}
         >
           I can be dragged
         </Draggable>
       }
    </Droppable>

</DragDropContext >

// footerDroppable.js


    <Droppable droppableId="footerDrop">
       {provided => 
        <Draggable 
           ref={provided.innerRef} 
           {...provided.draggableProps} 
           {...other props}
         >
           I'm a footer drag
         </Draggable>
       }
    </Droppable>

</DragDropContext >

// 结构

<div>
  <Sidebar> // first drag context
  <div>
    <footer>
       <other elements />
       <FooterDroppable /> // second drag context
    <footer>
  <div/>

我可以将可拖动的元素从页脚移动到侧边栏/反之亦然?

当然,我可以只移动DragDropContext两个组件的父级(我知道该怎么做),但是除了有一个父级之外还有其他DragDropContext方法吗?

PS上面的代码不是确切的结构/代码,而是更像一个原型,所以你可以可视化,因为我正在开发一个更大的应用程序。

4

2 回答 2

3

As you stated, you can have a single DragDropContext to handle d'n'd between multiple Droppable.

And there's no other way to do it (right now) with react-beautiful-dnd.

于 2020-05-06T12:26:21.520 回答
0

试试这个选项https://react-beautiful-dnd.netlify.app/?path=/story/multiple-horizo ​​ntal-lists--stress-test from beautiful-dnd

于 2022-02-23T06:59:56.760 回答