增加children节点变化时,将节点的位置记录下来

This commit is contained in:
wanghaoo 2019-01-25 13:35:19 +08:00
parent 1bf8ac2966
commit 669ce36fba
4 changed files with 19 additions and 4 deletions

View File

@ -67,6 +67,8 @@ var Tree = function (_React$Component) {
var checkedKeys = this.getDefaultCheckedKeys(nextProps, true);
var selectedKeys = this.getDefaultSelectedKeys(nextProps, true);
var st = {};
// 用于记录这次data内容有没有变化
this.dataChange = false;
if (expandedKeys) {
st.expandedKeys = expandedKeys;
}
@ -81,6 +83,9 @@ var Tree = function (_React$Component) {
if (selectedKeys) {
st.selectedKeys = selectedKeys;
}
if (nextProps.children !== this.props.children) {
this.dataChange = true;
}
this.setState(st);
};
@ -775,7 +780,7 @@ var Tree = function (_React$Component) {
};
});
};
if (props.showLine && !props.checkable) {
if (props.showLine && !props.checkable || this.dataChange) {
getTreeNodesStates();
}
if (props.checkable && (this.checkedKeysChange || props.loadData)) {

7
dist/demo.js vendored
View File

@ -8254,6 +8254,8 @@
var checkedKeys = this.getDefaultCheckedKeys(nextProps, true);
var selectedKeys = this.getDefaultSelectedKeys(nextProps, true);
var st = {};
// 用于记录这次data内容有没有变化
this.dataChange = false;
if (expandedKeys) {
st.expandedKeys = expandedKeys;
}
@ -8268,6 +8270,9 @@
if (selectedKeys) {
st.selectedKeys = selectedKeys;
}
if (nextProps.children !== this.props.children) {
this.dataChange = true;
}
this.setState(st);
};
@ -8962,7 +8967,7 @@
};
});
};
if (props.showLine && !props.checkable) {
if (props.showLine && !props.checkable || this.dataChange) {
getTreeNodesStates();
}
if (props.checkable && (this.checkedKeysChange || props.loadData)) {

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -42,6 +42,8 @@ class Tree extends React.Component {
const checkedKeys = this.getDefaultCheckedKeys(nextProps, true);
const selectedKeys = this.getDefaultSelectedKeys(nextProps, true);
const st = {};
// 用于记录这次data内容有没有变化
this.dataChange = false;
if (expandedKeys) {
st.expandedKeys = expandedKeys;
}
@ -56,6 +58,9 @@ class Tree extends React.Component {
if (selectedKeys) {
st.selectedKeys = selectedKeys;
}
if(nextProps.children !== this.props.children){
this.dataChange = true;
}
this.setState(st);
}
@ -747,7 +752,7 @@ onExpand(treeNode,keyType) {
};
});
};
if (props.showLine && !props.checkable) {
if (props.showLine && !props.checkable || this.dataChange) {
getTreeNodesStates();
}
if (props.checkable && (this.checkedKeysChange || props.loadData)) {