【发布时间】:2019-06-24 15:39:26
【问题描述】:
我尝试使用 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>
【问题讨论】:
标签: javascript reactjs drag-and-drop