Browse Source

update tree draggable demo

pull/12826/head
zombiej 6 years ago
parent
commit
bc35582643
  1. 31
      components/tree/demo/draggable.md

31
components/tree/demo/draggable.md

@ -66,7 +66,7 @@ class Demo extends React.Component {
const dragKey = info.dragNode.props.eventKey; const dragKey = info.dragNode.props.eventKey;
const dropPos = info.node.props.pos.split('-'); const dropPos = info.node.props.pos.split('-');
const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]);
// const dragNodesKeys = info.dragNodesKeys;
const loop = (data, key, callback) => { const loop = (data, key, callback) => {
data.forEach((item, index, arr) => { data.forEach((item, index, arr) => {
if (item.key === key) { if (item.key === key) {
@ -78,12 +78,32 @@ class Demo extends React.Component {
}); });
}; };
const data = [...this.state.gData]; const data = [...this.state.gData];
// Find dragObject
let dragObj; let dragObj;
loop(data, dragKey, (item, index, arr) => { loop(data, dragKey, (item, index, arr) => {
arr.splice(index, 1); arr.splice(index, 1);
dragObj = item; 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 ar;
let i; let i;
loop(data, dropKey, (item, index, arr) => { loop(data, dropKey, (item, index, arr) => {
@ -95,13 +115,8 @@ class Demo extends React.Component {
} else { } else {
ar.splice(i + 1, 0, dragObj); ar.splice(i + 1, 0, dragObj);
} }
} else {
loop(data, dropKey, (item) => {
item.children = item.children || [];
// where to insert 示例添加到尾部,可以是随意位置
item.children.push(dragObj);
});
} }
this.setState({ this.setState({
gData: data, gData: data,
}); });

Loading…
Cancel
Save