From bc35582643b760b35247875463245be1e5a9e2b0 Mon Sep 17 00:00:00 2001 From: zombiej Date: Thu, 25 Oct 2018 11:19:17 +0800 Subject: [PATCH] update tree draggable demo --- components/tree/demo/draggable.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/components/tree/demo/draggable.md b/components/tree/demo/draggable.md index 1cf352603b..ff8977a4ca 100644 --- a/components/tree/demo/draggable.md +++ b/components/tree/demo/draggable.md @@ -66,7 +66,7 @@ class Demo extends React.Component { const dragKey = info.dragNode.props.eventKey; const dropPos = info.node.props.pos.split('-'); const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); - // const dragNodesKeys = info.dragNodesKeys; + const loop = (data, key, callback) => { data.forEach((item, index, arr) => { if (item.key === key) { @@ -78,12 +78,32 @@ class Demo extends React.Component { }); }; const data = [...this.state.gData]; + + // Find dragObject let dragObj; loop(data, dragKey, (item, index, arr) => { arr.splice(index, 1); dragObj = item; }); - if (info.dropToGap) { + + if (!info.dropToGap) { + // Drop on the content + loop(data, dropKey, (item) => { + item.children = item.children || []; + // where to insert 示例添加到尾部,可以是随意位置 + item.children.push(dragObj); + }); + } else if ( + (info.node.props.children || []).length > 0 // Has children + && info.node.props.expanded // Is expanded + && dropPosition === 1 // On the bottom gap + ) { + loop(data, dropKey, (item) => { + item.children = item.children || []; + // where to insert 示例添加到尾部,可以是随意位置 + item.children.unshift(dragObj); + }); + } else { let ar; let i; loop(data, dropKey, (item, index, arr) => { @@ -95,13 +115,8 @@ class Demo extends React.Component { } else { ar.splice(i + 1, 0, dragObj); } - } else { - loop(data, dropKey, (item) => { - item.children = item.children || []; - // where to insert 示例添加到尾部,可以是随意位置 - item.children.push(dragObj); - }); } + this.setState({ gData: data, });