This commit is contained in:
ahua52 2017-09-07 18:13:10 +08:00
parent 0691a17b7a
commit 3ac3d886c7
3 changed files with 45 additions and 53 deletions

View File

@ -249,16 +249,14 @@ var Tree = function (_React$Component) {
this.props.onCheck((0, _util.getStrictlyValue)(checkedKeys, this.props.checkedKeys.halfChecked), newSt); this.props.onCheck((0, _util.getStrictlyValue)(checkedKeys, this.props.checkedKeys.halfChecked), newSt);
} else { } else {
if (checked && index === -1) { if (checked && index === -1) {
(function () { this.treeNodesStates[treeNode.props.pos].checked = true;
_this3.treeNodesStates[treeNode.props.pos].checked = true; var checkedPositions = [];
var checkedPositions = []; Object.keys(this.treeNodesStates).forEach(function (i) {
Object.keys(_this3.treeNodesStates).forEach(function (i) { if (_this3.treeNodesStates[i].checked) {
if (_this3.treeNodesStates[i].checked) { checkedPositions.push(i);
checkedPositions.push(i); }
} });
}); (0, _util.handleCheckState)(this.treeNodesStates, (0, _util.filterParentPosition)(checkedPositions), true);
(0, _util.handleCheckState)(_this3.treeNodesStates, (0, _util.filterParentPosition)(checkedPositions), true);
})();
} }
if (!checked) { if (!checked) {
this.treeNodesStates[treeNode.props.pos].checked = false; this.treeNodesStates[treeNode.props.pos].checked = false;
@ -567,37 +565,33 @@ var Tree = function (_React$Component) {
this.halfCheckedKeys = props._treeNodesStates.halfCheckedKeys; this.halfCheckedKeys = props._treeNodesStates.halfCheckedKeys;
this.checkedKeys = props._treeNodesStates.checkedKeys; this.checkedKeys = props._treeNodesStates.checkedKeys;
} else { } else {
(function () { var checkedKeys = this.state.checkedKeys;
var checkedKeys = _this4.state.checkedKeys; var checkKeys = void 0;
var checkKeys = void 0; if (!props.loadData && this.checkKeys && this._checkedKeys && (0, _util.arraysEqual)(this._checkedKeys, checkedKeys)) {
if (!props.loadData && _this4.checkKeys && _this4._checkedKeys && (0, _util.arraysEqual)(_this4._checkedKeys, checkedKeys)) { // if checkedKeys the same as _checkedKeys from onCheck, use _checkedKeys.
// if checkedKeys the same as _checkedKeys from onCheck, use _checkedKeys. checkKeys = this.checkKeys;
checkKeys = _this4.checkKeys; } else {
} else { var checkedPositions = [];
(function () { this.treeNodesStates = {};
var checkedPositions = []; (0, _util.loopAllChildren)(props.children, function (item, index, pos, keyOrPos, siblingPosition) {
_this4.treeNodesStates = {}; _this4.treeNodesStates[pos] = {
(0, _util.loopAllChildren)(props.children, function (item, index, pos, keyOrPos, siblingPosition) { node: item,
_this4.treeNodesStates[pos] = { key: keyOrPos,
node: item, checked: false,
key: keyOrPos, halfChecked: false,
checked: false, siblingPosition: siblingPosition
halfChecked: false, };
siblingPosition: siblingPosition if (checkedKeys.indexOf(keyOrPos) !== -1) {
}; _this4.treeNodesStates[pos].checked = true;
if (checkedKeys.indexOf(keyOrPos) !== -1) { checkedPositions.push(pos);
_this4.treeNodesStates[pos].checked = true; }
checkedPositions.push(pos); });
} // if the parent node's key exists, it all children node will be checked
}); (0, _util.handleCheckState)(this.treeNodesStates, (0, _util.filterParentPosition)(checkedPositions), true);
// if the parent node's key exists, it all children node will be checked checkKeys = (0, _util.getCheck)(this.treeNodesStates);
(0, _util.handleCheckState)(_this4.treeNodesStates, (0, _util.filterParentPosition)(checkedPositions), true); }
checkKeys = (0, _util.getCheck)(_this4.treeNodesStates); this.halfCheckedKeys = checkKeys.halfCheckedKeys;
})(); this.checkedKeys = checkKeys.checkedKeys;
}
_this4.halfCheckedKeys = checkKeys.halfCheckedKeys;
_this4.checkedKeys = checkKeys.checkedKeys;
})();
} }
} }

View File

@ -157,17 +157,15 @@ var TreeNode = function (_React$Component) {
var callbackPromise = this.props.root.onExpand(this); var callbackPromise = this.props.root.onExpand(this);
if (callbackPromise && (typeof callbackPromise === 'undefined' ? 'undefined' : _typeof(callbackPromise)) === 'object') { if (callbackPromise && (typeof callbackPromise === 'undefined' ? 'undefined' : _typeof(callbackPromise)) === 'object') {
(function () { var setLoading = function setLoading(dataLoading) {
var setLoading = function setLoading(dataLoading) { _this2.setState({ dataLoading: dataLoading });
_this2.setState({ dataLoading: dataLoading }); };
}; setLoading(true);
setLoading(true); callbackPromise.then(function () {
callbackPromise.then(function () { setLoading(false);
setLoading(false); }, function () {
}, function () { setLoading(false);
setLoading(false); });
});
})();
} }
}; };

File diff suppressed because one or more lines are too long