From 2e0a253cd48c38a515a3a684b103cfd6d21124b4 Mon Sep 17 00:00:00 2001 From: zsmj Date: Wed, 21 Sep 2022 21:37:39 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-12891=20feat:=20treevaluechooser?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5=E6=95=B0=E7=BB=84=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../abstract.treevaluechooser.js | 29 +++++++++++++++++++ .../treevaluechooser/pane.treevaluechooser.js | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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);