fix:解决树状表,不传 onExpandedRowsChange 属性,展不开节点的问题

This commit is contained in:
yangchch6 2019-11-30 14:16:43 +08:00
parent 9fa006ea36
commit fcbe1c9c70
4 changed files with 53 additions and 46 deletions

View File

@ -112,7 +112,7 @@ function bigData(Table) {
_this.setStartAndEndIndex(currentIndex, dataLen);
}
if (newExpandedKeys !== props.expandedRowKeys) {
_this.cacheExpandedKeys = newExpandedKeys;
_this.cacheExpandedKeys = new Set(newExpandedKeys);
//重新递归数据
var flatTreeData = _this.deepTraversal(data);
var sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
@ -402,6 +402,7 @@ function bigData(Table) {
_this$expandedRowKeys = _this.expandedRowKeys,
expandedRowKeys = _this$expandedRowKeys === undefined ? [] : _this$expandedRowKeys,
flatTreeKeysMap = _this.flatTreeKeysMap,
expandedKeysSet = cacheExpandedKeys ? cacheExpandedKeys : new Set(expandedRowKeys),
flatTreeData = [],
dataCopy = treeData;
@ -410,11 +411,11 @@ function bigData(Table) {
var _dataCopy$i = dataCopy[i],
key = _dataCopy$i.key,
children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]);
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
dataCopyI = new Object(),
isLeaf = children ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
var dataCopyI = new Object();
var isLeaf = children ? false : true,
isExpanded = cacheExpandedKeys ? cacheExpandedKeys.indexOf(key) !== -1 : expandedRowKeys.indexOf(key) !== -1;
dataCopyI = _extends(dataCopyI, {
key: key,
isExpanded: isExpanded,
@ -642,20 +643,21 @@ function bigData(Table) {
_this4.setState({ needRender: !needRender });
}
}
if (_this4.treeType) {
//收起和展开时,缓存 expandedKeys
_this.cacheExpandedKeys = expandedRowKeys;
//重新递归数据
var flatTreeData = _this.deepTraversal(data);
var sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
_this.flatTreeData = flatTreeData;
_this.handleTreeListChange(sliceTreeList);
_this.cacheExpandedKeys = null;
}
}
// expandState为true时记录下
_this.props.onExpand(expandState, record);
if (_this4.treeType) {
//收起和展开时,缓存 expandedKeys
_this.cacheExpandedKeys = new Set(expandedRowKeys);
//重新递归数据
var flatTreeData = _this.deepTraversal(data);
var sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
_this.flatTreeData = flatTreeData;
_this.handleTreeListChange(sliceTreeList);
_this.cacheExpandedKeys = null;
}
};
}, _temp;
}

32
dist/demo.js vendored
View File

@ -289702,7 +289702,7 @@
_this.setStartAndEndIndex(currentIndex, dataLen);
}
if (newExpandedKeys !== props.expandedRowKeys) {
_this.cacheExpandedKeys = newExpandedKeys;
_this.cacheExpandedKeys = new Set(newExpandedKeys);
//重新递归数据
var flatTreeData = _this.deepTraversal(data);
var sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
@ -289992,6 +289992,7 @@
_this$expandedRowKeys = _this.expandedRowKeys,
expandedRowKeys = _this$expandedRowKeys === undefined ? [] : _this$expandedRowKeys,
flatTreeKeysMap = _this.flatTreeKeysMap,
expandedKeysSet = cacheExpandedKeys ? cacheExpandedKeys : new Set(expandedRowKeys),
flatTreeData = [],
dataCopy = treeData;
@ -290000,11 +290001,11 @@
var _dataCopy$i = dataCopy[i],
key = _dataCopy$i.key,
children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]);
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
dataCopyI = new Object(),
isLeaf = children ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
var dataCopyI = new Object();
var isLeaf = children ? false : true,
isExpanded = cacheExpandedKeys ? cacheExpandedKeys.indexOf(key) !== -1 : expandedRowKeys.indexOf(key) !== -1;
dataCopyI = _extends(dataCopyI, {
key: key,
isExpanded: isExpanded,
@ -290232,20 +290233,21 @@
_this4.setState({ needRender: !needRender });
}
}
if (_this4.treeType) {
//收起和展开时,缓存 expandedKeys
_this.cacheExpandedKeys = expandedRowKeys;
//重新递归数据
var flatTreeData = _this.deepTraversal(data);
var sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
_this.flatTreeData = flatTreeData;
_this.handleTreeListChange(sliceTreeList);
_this.cacheExpandedKeys = null;
}
}
// expandState为true时记录下
_this.props.onExpand(expandState, record);
if (_this4.treeType) {
//收起和展开时,缓存 expandedKeys
_this.cacheExpandedKeys = new Set(expandedRowKeys);
//重新递归数据
var flatTreeData = _this.deepTraversal(data);
var sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
_this.flatTreeData = flatTreeData;
_this.handleTreeListChange(sliceTreeList);
_this.cacheExpandedKeys = null;
}
};
}, _temp;
}

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -85,7 +85,7 @@ export default function bigData(Table) {
_this.setStartAndEndIndex(currentIndex,dataLen);
}
if(newExpandedKeys !== props.expandedRowKeys){
_this.cacheExpandedKeys = newExpandedKeys;
_this.cacheExpandedKeys = new Set(newExpandedKeys);
//重新递归数据
let flatTreeData = _this.deepTraversal(data);
let sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
@ -130,14 +130,16 @@ export default function bigData(Table) {
deepTraversal = (treeData, parentKey=null, isShown) => {
const _this = this;
let {cacheExpandedKeys, expandedRowKeys = [], flatTreeKeysMap} = _this,
expandedKeysSet = cacheExpandedKeys ? cacheExpandedKeys : new Set(expandedRowKeys),
flatTreeData = [],
dataCopy = treeData;
if(Array.isArray(dataCopy)){
for (let i=0, l=dataCopy.length; i<l; i++) {
let { key, children, ...props } = dataCopy[i];
let dataCopyI = new Object();
let isLeaf = children ? false : true,
isExpanded = cacheExpandedKeys ? cacheExpandedKeys.indexOf(key) !== -1 : expandedRowKeys.indexOf(key) !== -1;
let { key, children, ...props } = dataCopy[i],
dataCopyI = new Object(),
isLeaf = children ? false : true,
//如果父节点是收起状态,则子节点的展开状态无意义。(一级节点或根节点直接判断自身状态即可)
isExpanded = (parentKey === null || expandedKeysSet.has(parentKey)) ? expandedKeysSet.has(key) : false;
dataCopyI = Object.assign(dataCopyI,{
key,
isExpanded,
@ -517,20 +519,21 @@ export default function bigData(Table) {
this.setState({ needRender: !needRender });
}
}
if(this.treeType) {
//收起和展开时,缓存 expandedKeys
_this.cacheExpandedKeys = expandedRowKeys;
//重新递归数据
let flatTreeData = _this.deepTraversal(data);
let sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
_this.flatTreeData = flatTreeData;
_this.handleTreeListChange(sliceTreeList);
_this.cacheExpandedKeys = null;
}
}
// expandState为true时记录下
_this.props.onExpand(expandState, record);
if(this.treeType) {
//收起和展开时,缓存 expandedKeys
_this.cacheExpandedKeys = new Set(expandedRowKeys);
//重新递归数据
let flatTreeData = _this.deepTraversal(data);
let sliceTreeList = flatTreeData.slice(_this.startIndex, _this.endIndex);
_this.flatTreeData = flatTreeData;
_this.handleTreeListChange(sliceTreeList);
_this.cacheExpandedKeys = null;
}
};