Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Oct 25, 2018
1 parent 2000d94 commit 8ad6785
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions examples/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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) {
Expand All @@ -40,12 +40,33 @@ 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 {
// Drop on the gap
let ar;
let i;
loop(data, dropKey, (item, index, arr) => {
Expand All @@ -57,13 +78,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,
});
Expand Down

0 comments on commit 8ad6785

Please sign in to comment.