mirror of https://github.com/ElemeFE/element
Fix Tree Bug: set data does not work
parent
8af8c8b8fe
commit
cd7156cb03
|
@ -28,7 +28,7 @@ const reInitChecked = function(node) {
|
||||||
|
|
||||||
const getPropertyFromData = function(node, prop) {
|
const getPropertyFromData = function(node, prop) {
|
||||||
const props = node.props;
|
const props = node.props;
|
||||||
const data = node.data;
|
const data = node.data || {};
|
||||||
const config = props[prop];
|
const config = props[prop];
|
||||||
|
|
||||||
if (typeof config === 'function') {
|
if (typeof config === 'function') {
|
||||||
|
@ -69,23 +69,28 @@ export default class Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lazy !== true && this.data) {
|
if (this.lazy !== true && this.data) {
|
||||||
let children;
|
this.setData(this.data);
|
||||||
if (this.level === -1 && this.data instanceof Array) {
|
}
|
||||||
children = this.data;
|
}
|
||||||
} else {
|
|
||||||
children = getPropertyFromData(this, 'children') || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0, j = children.length; i < j; i++) {
|
setData(data) {
|
||||||
const child = children[i];
|
this.data = data;
|
||||||
this.insertChild(new Node({
|
let children;
|
||||||
data: child,
|
if (this.level === -1 && this.data instanceof Array) {
|
||||||
parent: this,
|
children = this.data;
|
||||||
lazy: this.lazy,
|
} else {
|
||||||
load: this.load,
|
children = getPropertyFromData(this, 'children') || [];
|
||||||
props: this.props
|
}
|
||||||
}));
|
|
||||||
}
|
for (let i = 0, j = children.length; i < j; i++) {
|
||||||
|
const child = children[i];
|
||||||
|
this.insertChild(new Node({
|
||||||
|
data: child,
|
||||||
|
parent: this,
|
||||||
|
lazy: this.lazy,
|
||||||
|
load: this.load,
|
||||||
|
props: this.props
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
data(newVal) {
|
||||||
|
this.tree.root.setData(newVal);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
getCheckedNodes(leafOnly) {
|
getCheckedNodes(leafOnly) {
|
||||||
return this.tree.getCheckedNodes(leafOnly);
|
return this.tree.getCheckedNodes(leafOnly);
|
||||||
|
|
Loading…
Reference in New Issue