Browse Source

REPORT-46068 fix: 节点状态判断时进行深度比较

es6
iapyang 4 years ago
parent
commit
607eaf694d
  1. 31
      src/component/treevaluechooser/abstract.treevaluechooser.js

31
src/component/treevaluechooser/abstract.treevaluechooser.js

@ -598,11 +598,15 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
} }
function dealWithSelectedValue(parentValues, selectedValues) { function dealWithSelectedValue(parentValues, selectedValues) {
var valueMap = {}; var valueMap = {}, parents = BI.deepClone(parentValues);
BI.each(parentValues, function (i, v) { BI.each(parentValues, function (i, v) {
parents.push(v);
selectedValues = selectedValues[v] || {}; selectedValues = selectedValues[v] || {};
}); });
BI.each(selectedValues, function (value, obj) { BI.each(selectedValues, function (value, obj) {
var currentParents = BI.concat(parents, value);
if (BI.isNull(obj)) { if (BI.isNull(obj)) {
valueMap[value] = [0, 0]; valueMap[value] = [0, 0];
return; return;
@ -615,6 +619,8 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
BI.each(obj, function (t, o) { BI.each(obj, function (t, o) {
if (BI.isNull(o) || BI.isEmpty(o)) { if (BI.isNull(o) || BI.isEmpty(o)) {
nextNames[t] = true; nextNames[t] = true;
} else {
isAllSelected(o, BI.concat(currentParents, [t])) && (nextNames[t] = true);
} }
}); });
// valueMap的数组第一个参数为不选: 0, 半选: 1, 全选:2, 第二个参数为改节点下选中的子节点个数(子节点全选或者不存在) // valueMap的数组第一个参数为不选: 0, 半选: 1, 全选:2, 第二个参数为改节点下选中的子节点个数(子节点全选或者不存在)
@ -623,6 +629,24 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return valueMap; return valueMap;
} }
function isAllSelected(selected, parents) {
if (BI.isEmpty(selected)) {
return true;
}
if (self._getChildCount(parents) !== BI.size(selected)) {
return false;
}
var can = true;
BI.each(selected, function (value) {
can = can && isAllSelected(selected[value], BI.concat(parents, value));
});
return can;
}
function getCheckState(current, parentValues, valueMap, checkState) { function getCheckState(current, parentValues, valueMap, checkState) {
// 节点本身的checked和half优先级最高 // 节点本身的checked和half优先级最高
var checked = checkState.checked, half = checkState.half; var checked = checkState.checked, half = checkState.half;
@ -758,7 +782,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return true; return true;
}); });
return findParentNode; return findParentNode;
}, },
@ -769,7 +793,8 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
} else { } else {
var parent = this.tree.getRoot(); var parent = this.tree.getRoot();
} }
return parent.getChildren();
return parent ? parent.getChildren() : [];
}, },
_getAllChildren: function(parentValues) { _getAllChildren: function(parentValues) {

Loading…
Cancel
Save