Browse Source

KERNEL-12891 feat: treevaluechooser支持传入数组类型的value

es6
zsmj 2 years ago
parent
commit
2e0a253cd4
  1. 29
      src/component/treevaluechooser/abstract.treevaluechooser.js
  2. 3
      src/component/treevaluechooser/pane.treevaluechooser.js

29
src/component/treevaluechooser/abstract.treevaluechooser.js

@ -851,6 +851,35 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return this._getChildren(parentValues).length;
},
assertSelectedValue: function (selectedValues, items = []) {
if (BI.isPlainObject(selectedValues)) {
return selectedValues;
}
var tree = BI.Tree.transformToTreeFormat(items);
var value2ParentMap = {};
BI.Tree.traversal(tree, function (index, node, pNode) {
value2ParentMap[node.value] = pNode;
});
var result = {};
BI.each(selectedValues, function (index, value) {
var curr = value;
var parentPath = [];
while (curr) {
parentPath.unshift(curr);
curr = value2ParentMap[curr]?.value;
}
BI.each(parentPath, function (index) {
if (BI.isNull(BI.get(result, parentPath.slice(0, index + 1)))) {
BI.set(result, parentPath.slice(0, index + 1), {});
}
});
});
return result;
},
buildCompleteTree: function (selectedValues) {
var self = this;
var result = {};

3
src/component/treevaluechooser/pane.treevaluechooser.js

@ -30,7 +30,8 @@ BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, {
self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE);
});
if (BI.isNotNull(o.value)) {
this.pane.setSelectedValue(o.value);
var selectedValues = this.assertSelectedValue(o.value, o.items);
this.pane.setSelectedValue(selectedValues);
}
if (BI.isNotNull(o.items)) {
this._initData(o.items);

Loading…
Cancel
Save