diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index 53e31298f..dbd1453b8 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/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 = {}; diff --git a/src/component/treevaluechooser/pane.treevaluechooser.js b/src/component/treevaluechooser/pane.treevaluechooser.js index 66486711a..8171c04d8 100644 --- a/src/component/treevaluechooser/pane.treevaluechooser.js +++ b/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);