javascript - 组件不会掉落在相邻列中react-beautiful-dnd

标签 javascript reactjs react-beautiful-dnd

我在将组件放入应用程序的下一个列表区域时遇到困难。 我可以在父列中完美地拖放和排序,但无法将组件放在其他地方。这是我的 onDragEnd 函数中的代码:

  onDragEnd = result => {
    const {destination, source, draggableId} = result
    if(!destination) return
    let start = this.state.list[parseInt(source.droppableId)]
    let finish = this.state.list[parseInt(destination.droppableId)]

    if(start === finish){ // this works
      let updatedList = this.state.list.map(obj => {
        if(obj.id === parseInt(source.droppableId)){
          let a0 = obj.cards.splice(source.index,1)
          obj.cards.splice(destination.index,0,a0[0])
          obj.cards.map((o,i) => o.id = i)
        }
        return obj
      })
      this.setState({list:updatedList})
    }
   else { // this doesn't
     let updatedList = this.state.list.map(obj => {
      if(obj.id === parseInt(source.droppableId)){
        let a0 = obj.cards.splice(source.index,1)
        obj.cards.map((o,i) => o.id = i)
        this.state.list[parseInt(destination.droppableId)].cards.splice(destination.index,0,a0[0])
        this.state.list[parseInt(destination.droppableId)].cards.map((o,i) => o.id = i)
      }
      return obj
    })
    this.setState({list:updatedList})
   }
  }

根据我一直在使用的教程,我猜我只需要更改状态...我已经记录了几乎所有内容并检查了状态是否存在异常,但我没有看到问题。我的演示代码可以找到here 。谢谢。

最佳答案

只需为 Droppable 组件指定一个固定的高度,甚至是一个minHeight

试试这个https://codesandbox.io/s/1vp4835x7l

关于javascript - 组件不会掉落在相邻列中react-beautiful-dnd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55444705/

相关文章:

reactjs - 用于脚本加载的模拟实用程序函数

javascript - 使用 react-beautiful-dnd 更改拖放区中的元素大小

javascript - 为什么 ("a"中的 ["a","b"]) 产生假,而 (1 in [1,2]) 产生真?

javascript - 我无法找出为什么 req.param ('length' ) 返回 0

react 中的CSS网格动画

javascript - 通过 map 标记导航到react-router URL

javascript - Sortablejs 根据与边缘的距离自动滚动速度

javascript - 无法读取房地产谷歌图表

javascript - 如何在保持数据状态有序的同时保持接收数据?