fix:更新时 treeData 加判断

This commit is contained in:
yangchch6 2019-08-20 09:46:20 +08:00
parent d91db60e51
commit 101756fa84
7 changed files with 22 additions and 11 deletions

View File

@ -136,7 +136,7 @@ var Tree = function (_React$Component) {
if (selectedKeys) {
st.selectedKeys = selectedKeys;
}
if (nextProps.treeData !== this.props.treeData) {
if (nextProps.hasOwnProperty('treeData') && nextProps.treeData !== this.props.treeData) {
this.dataChange = true;
st.treeData = treeData;
}
@ -1217,7 +1217,7 @@ Tree.propTypes = {
openAnimation: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].object]),
lazyLoad: _propTypes2["default"].bool,
treeData: _propTypes2["default"].array,
renderTreeNode: _propTypes2["default"].func
renderTreeNodes: _propTypes2["default"].func
};
Tree.defaultProps = {

View File

@ -393,12 +393,17 @@ function convertListToTree(treeData, attr, flatTreeKeysMap) {
var findParentNode = function findParentNode(node) {
var parentKey = node[attr.parendId];
if (!resKeysMap.hasOwnProperty(parentKey)) {
var key = node.key,
title = node.title,
children = node.children,
otherProps = _objectWithoutProperties(node, ['key', 'title', 'children']);
var obj = {
key: flatTreeKeysMap[parentKey][attr.id],
title: flatTreeKeysMap[parentKey][attr.name],
children: []
};
tree.push(obj);
tree.push(_extends(obj, _extends({}, otherProps)));
resKeysMap[obj.key] = obj;
}
return flatTreeKeysMap[parentKey];

11
dist/demo.js vendored
View File

@ -34482,7 +34482,7 @@
if (selectedKeys) {
st.selectedKeys = selectedKeys;
}
if (nextProps.treeData !== this.props.treeData) {
if (nextProps.hasOwnProperty('treeData') && nextProps.treeData !== this.props.treeData) {
this.dataChange = true;
st.treeData = treeData;
}
@ -35563,7 +35563,7 @@
openAnimation: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].object]),
lazyLoad: _propTypes2['default'].bool,
treeData: _propTypes2['default'].array,
renderTreeNode: _propTypes2['default'].func
renderTreeNodes: _propTypes2['default'].func
};
Tree.defaultProps = {
@ -36578,12 +36578,17 @@
var findParentNode = function findParentNode(node) {
var parentKey = node[attr.parendId];
if (!resKeysMap.hasOwnProperty(parentKey)) {
var key = node.key,
title = node.title,
children = node.children,
otherProps = _objectWithoutProperties(node, ['key', 'title', 'children']);
var obj = {
key: flatTreeKeysMap[parentKey][attr.id],
title: flatTreeKeysMap[parentKey][attr.name],
children: []
};
tree.push(obj);
tree.push(_extends(obj, _extends({}, otherProps)));
resKeysMap[obj.key] = obj;
}
return flatTreeKeysMap[parentKey];

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "bee-tree",
"version": "2.1.0-beta.0",
"version": "2.1.0-beta.2",
"description": "Tree ui component for react",
"keywords": [
"react",

View File

@ -93,7 +93,7 @@ class Tree extends React.Component {
if (selectedKeys) {
st.selectedKeys = selectedKeys;
}
if(nextProps.treeData !== this.props.treeData){
if(nextProps.hasOwnProperty('treeData') && nextProps.treeData !== this.props.treeData){
this.dataChange = true;
st.treeData = treeData;
}
@ -1128,7 +1128,7 @@ Tree.propTypes = {
openAnimation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
lazyLoad: PropTypes.bool,
treeData: PropTypes.array,
renderTreeNode: PropTypes.func
renderTreeNodes: PropTypes.func
};
Tree.defaultProps = {

View File

@ -340,12 +340,13 @@ export function convertListToTree(treeData, attr, flatTreeKeysMap) {
let findParentNode = (node) => {
let parentKey = node[attr.parendId];
if (!resKeysMap.hasOwnProperty(parentKey) ) {
let { key, title, children, ...otherProps } = node;
let obj = {
key: flatTreeKeysMap[parentKey][attr.id],
title: flatTreeKeysMap[parentKey][attr.name],
children: []
};
tree.push(obj);
tree.push(Object.assign(obj, {...otherProps}));
resKeysMap[obj.key] = obj;
}
return flatTreeKeysMap[parentKey];