我是 react-grid-layout 的新手,我使用此示例创建了一个拖放示例示例https://react-grid-layout.github.io/react-grid-layout/examples/15-drag-from -outside.html。当项目被删除时,它总是放置在网格的第一列。警报中的 X 和 Y 是正确的,我的代码有什么问题?这是我的代码:
onDrop = (layout, layoutItem, _event) => {
alert(`Dropped element props:\n${JSON.stringify(layoutItem, ['x',
'y', 'w', 'h'], 2)}`);
this.setState(prevState => ({
layouts: {
...prevState.layouts,
[prevState.currentBreakpoint]: [
...prevState.layouts[prevState.currentBreakpoint],
layoutItem
]
}
}));
};
render() {
return (
<div>
<div className="toolBar">
<div
className="droppable-element"
draggable={true}
unselectable="on"
>
Button 1
</div>
</div>
<div>
<ResponsiveReactGridLayout
{...this.props}
layouts={this.state.layouts}
onBreakpointChange={this.onBreakpointChange}
onLayoutChange={this.onLayoutChange}
onDrop={this.onDrop}
droppingItem={this.props.item}
measureBeforeMount={false}
useCSSTransforms={this.state.mounted}
compactType={this.state.compactType}
preventCollision={true}
isDroppable={true}
>
{this.generateDOM()}
</ResponsiveReactGridLayout>
</div>
</div>
);
}