update Tree Render function
This commit is contained in:
parent
97098fcd85
commit
6ff0e34003
3 changed files with 15 additions and 12 deletions
|
@ -146,7 +146,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
renderContent (h, { data, node }) {
|
renderContent (h, { data, node, root }) {
|
||||||
return h('span', {
|
return h('span', {
|
||||||
style: {
|
style: {
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
|
@ -169,7 +169,7 @@
|
||||||
marginRight: '8px'
|
marginRight: '8px'
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
click: () => { this.append(node, data) }
|
click: () => { this.append(data) }
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
h('Button', {
|
h('Button', {
|
||||||
|
@ -177,22 +177,23 @@
|
||||||
icon: 'ios-minus-empty'
|
icon: 'ios-minus-empty'
|
||||||
}),
|
}),
|
||||||
on: {
|
on: {
|
||||||
click: () => { this.remove(node, data) }
|
click: () => { this.remove(node, data, root) }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
append (node, data) {
|
append (data) {
|
||||||
this.$set(data, 'children', [{
|
this.$set(data, 'children', [{
|
||||||
title: 'appended node',
|
title: 'appended node',
|
||||||
expand: true
|
expand: true
|
||||||
}]);
|
}]);
|
||||||
},
|
},
|
||||||
remove (node, data) {
|
remove (node, data, root) {
|
||||||
const parent = node.parent;
|
const parentKey = root.find(el => el === node).parent;
|
||||||
console.log(node);
|
const parent = root.find(el => el.nodeKey === parentKey).node;
|
||||||
console.log(data);
|
const index = parent.children.indexOf(data);
|
||||||
|
parent.children.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,9 +113,10 @@
|
||||||
node () {
|
node () {
|
||||||
const Tree = findComponentUpward(this, 'Tree');
|
const Tree = findComponentUpward(this, 'Tree');
|
||||||
if (Tree) {
|
if (Tree) {
|
||||||
return Tree.flatState.find(item => item.nodeKey === this.data.nodeKey);
|
// 将所有的 node(即flatState)和当前 node 都传递
|
||||||
|
return [Tree.flatState, Tree.flatState.find(item => item.nodeKey === this.data.nodeKey)];
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,11 +4,12 @@ export default {
|
||||||
props: {
|
props: {
|
||||||
render: Function,
|
render: Function,
|
||||||
data: Object,
|
data: Object,
|
||||||
node: Object
|
node: Array
|
||||||
},
|
},
|
||||||
render: (h, ctx) => {
|
render: (h, ctx) => {
|
||||||
const params = {
|
const params = {
|
||||||
node: ctx.props.node,
|
root: ctx.props.node[0],
|
||||||
|
node: ctx.props.node[1],
|
||||||
data: ctx.props.data
|
data: ctx.props.data
|
||||||
};
|
};
|
||||||
return ctx.props.render(h, params);
|
return ctx.props.render(h, params);
|
||||||
|
|
Loading…
Add table
Reference in a new issue