Browse Source

Pull request #1718: REPORT-46068 节点状态判断时进行深度比较

Merge in VISUAL/fineui from ~TELLER/fineui:bugfix to master

* commit '80a11742bd435e5a04aba7d20416d9a75730371e':
  refactor: 优化写法
  refactor: 默认值
  REPORT-46068 fix: 节点状态判断时进行深度比较
  Revert "REPORT-46068 fix: 同步下拉树展开前使用重新计算的合并后的值"
  Revert "fix: 统一一下处理"
es6
Teller 4 years ago
parent
commit
98d9c65094
  1. 36
      src/component/treevaluechooser/abstract.treevaluechooser.js

36
src/component/treevaluechooser/abstract.treevaluechooser.js

@ -37,19 +37,10 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
if (!this.items) { if (!this.items) {
o.itemsCreator({}, function (items) { o.itemsCreator({}, function (items) {
self._initData(items); self._initData(items);
join(); call();
}); });
} else { } else {
join();
}
// 重新计算合并selectedValues
function join() {
self._reqAdjustTreeNode(options, function (joinedValue) {
options.selectedValues = joinedValue;
call(); call();
});
} }
function call() { function call() {
@ -607,11 +598,15 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
} }
function dealWithSelectedValue(parentValues, selectedValues) { function dealWithSelectedValue(parentValues, selectedValues) {
var valueMap = {}; var valueMap = {}, parents = (parentValues || []).slice(0);
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;
@ -624,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, 第二个参数为改节点下选中的子节点个数(子节点全选或者不存在)
@ -632,6 +629,20 @@ 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;
}
return BI.every(selected, function (value) {
return isAllSelected(selected[value], BI.concat(parents, value));
});
}
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;
@ -778,7 +789,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