我尝试使用 react-smooth-dnd 创建 dnd 编辑器。我有 2 个容器:第一个是带有元素的工具栏,第二个是编辑器。每个元素具有以下结构:
{
id: shortid.generate(),
type: 'TextElement',
options: {
text: 'Text',
style: {
padding: '10px 0 10px 15px'
},
isShowToolBar: false
}
}
当我尝试将元素从第一个容器复制到第二个容器时,我想更改id当前元素,但是当我尝试使用onDrop回调来执行此操作时,我只能更改id两个容器的每个元素。
如何id仅更改当前元素?
我的第一个(工具栏)容器是:
<Container
groupName="1"
behaviour="copy"
getChildPayload={i => this.state.items[i]}
>
{
this.state.items.map((element,i) => {
const component = createComponent(element, TYPE_TOOLBAR);
return (
<Draggable
key={i}
style={{display: 'inline-block', padding: '10px'}}
className="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-12"
>
{component}
</Draggable>
);
})
}
</Container>
我的第二个容器(编辑器):
<Container
groupName="1"
getChildPayload={i => this.state.items[i]}
onDrop={e => this.setState({
items: applyDrag(this.state.items, e)
})}
lockAxis="y"
dragHandleSelector=".element-drag-handler"
>
{
this.state.items.map((element, i) => {
const component = createComponent(
element,
TYPE_EDITOR,
this.elementToolBarHandler
);
return (
<Draggable key={i}>
{component}
</Draggable>
);
})
}
</Container>
智慧大石
相关分类