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: {
|
||||
renderContent (h, { data, node }) {
|
||||
renderContent (h, { data, node, root }) {
|
||||
return h('span', {
|
||||
style: {
|
||||
display: 'inline-block',
|
||||
|
@ -169,7 +169,7 @@
|
|||
marginRight: '8px'
|
||||
},
|
||||
on: {
|
||||
click: () => { this.append(node, data) }
|
||||
click: () => { this.append(data) }
|
||||
}
|
||||
}),
|
||||
h('Button', {
|
||||
|
@ -177,22 +177,23 @@
|
|||
icon: 'ios-minus-empty'
|
||||
}),
|
||||
on: {
|
||||
click: () => { this.remove(node, data) }
|
||||
click: () => { this.remove(node, data, root) }
|
||||
}
|
||||
})
|
||||
])
|
||||
]);
|
||||
},
|
||||
append (node, data) {
|
||||
append (data) {
|
||||
this.$set(data, 'children', [{
|
||||
title: 'appended node',
|
||||
expand: true
|
||||
}]);
|
||||
},
|
||||
remove (node, data) {
|
||||
const parent = node.parent;
|
||||
console.log(node);
|
||||
console.log(data);
|
||||
remove (node, data, root) {
|
||||
const parentKey = root.find(el => el === node).parent;
|
||||
const parent = root.find(el => el.nodeKey === parentKey).node;
|
||||
const index = parent.children.indexOf(data);
|
||||
parent.children.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,9 +113,10 @@
|
|||
node () {
|
||||
const Tree = findComponentUpward(this, '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 {
|
||||
return {};
|
||||
return [];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,11 +4,12 @@ export default {
|
|||
props: {
|
||||
render: Function,
|
||||
data: Object,
|
||||
node: Object
|
||||
node: Array
|
||||
},
|
||||
render: (h, ctx) => {
|
||||
const params = {
|
||||
node: ctx.props.node,
|
||||
root: ctx.props.node[0],
|
||||
node: ctx.props.node[1],
|
||||
data: ctx.props.data
|
||||
};
|
||||
return ctx.props.render(h, params);
|
||||
|
|
Loading…
Add table
Reference in a new issue