react-beautiful-dnd - 尝试添加或删除 Draggable... 拖动列时的警告

时间:2021-04-01 14:12:39

标签: javascript reactjs react-beautiful-dnd

在同一列表中拖放项目时出现此错误:

You are attempting to add or remove a Draggable [id: item-7]while a drag is occurring. This is only supported for virtual lists.

每次我拖放东西时,我都会为控制台中的每个项目获得 10-20 个... 我想知道是什么导致了这个问题?

这是我的 onDragEnd 函数:

const handleDragEnd = (result) => {
  const {destination, source, draggableId} = result;
  console.log('destination:', destination, 'source:', source, 'draggId:', draggableId)
  // if dragged outside list
  if(!destination){
    return
  }
  const sourceList = data.filter(list => list.id === source.droppableId);
  const destinationList = data.filter(list => list.id === destination.droppableId);
  const draggingItem = sourceList[0].items.filter(item => item.itemID === draggableId);

  console.log('source', sourceList ,'destinationList:', destinationList, 'draggging:', draggingItem)
  // if dragged in same list
  
   if(source.droppableId === destination.droppableId){
    sourceList[0].items.splice(source.index, 1)
    destinationList[0].items.splice(destination.index, 0 , draggingItem[0])
  }
}

0 个答案:

没有答案