diff --git a/src/widget/multilayerselecttree/multilayerselecttree.combo.js b/src/widget/multilayerselecttree/multilayerselecttree.combo.js index 57e2d775e8..bd12b25cfa 100644 --- a/src/widget/multilayerselecttree/multilayerselecttree.combo.js +++ b/src/widget/multilayerselecttree/multilayerselecttree.combo.js @@ -91,23 +91,9 @@ BI.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, { }; }, - _getSyncConfig: function () { - var o = this.options; - var baseConfig = this._getBaseConfig(); - baseConfig.el = { - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }; - return baseConfig; - }, - - _getAsyncConfig: function () { + _getSearchConfig: function() { var self = this, o = this.options; - var config = this._getBaseConfig(); - return BI.extend(config, { + return { el: { type: "bi.multilayer_select_tree_trigger", allowEdit: o.allowEdit, @@ -157,9 +143,28 @@ BI.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, { self.trigger.stopEditing(); } }] + } + }, + + _getSyncConfig: function () { + var o = this.options; + var baseConfig = this._getBaseConfig(); + return BI.extend(baseConfig, o.allowEdit ? this._getSearchConfig() : { + el: { + type: "bi.single_tree_trigger", + text: o.text, + height: o.height, + items: o.items, + value: o.value + } }); }, + _getAsyncConfig: function () { + var config = this._getBaseConfig(); + return BI.extend(config, this._getSearchConfig()); + }, + setValue: function (v) { v = BI.isArray(v) ? v : [v]; this.combo.setValue(v); diff --git a/src/widget/multilayerselecttree/multilayerselecttree.trigger.js b/src/widget/multilayerselecttree/multilayerselecttree.trigger.js index c953bed7fe..e91a6b4136 100644 --- a/src/widget/multilayerselecttree/multilayerselecttree.trigger.js +++ b/src/widget/multilayerselecttree/multilayerselecttree.trigger.js @@ -14,6 +14,10 @@ BI.MultiLayerSelectTreeTrigger = BI.inherit(BI.Trigger, { render: function () { var self = this, o = this.options; + if(o.itemsCreator === BI.emptyFn) { + this.tree = new BI.Tree(); + this.tree.initTree(BI.deepClone(BI.Tree.treeFormat(BI.deepClone(o.items)))); + } var content = { type: "bi.htape", items: [ @@ -68,7 +72,7 @@ BI.MultiLayerSelectTreeTrigger = BI.inherit(BI.Trigger, { if(o.itemsCreator === BI.emptyFn) { var finding = BI.Func.getSearchResult(o.items, keyword); var matched = finding.match, find = finding.find; - callback(find.concat(matched)); + callback(self._fillTreeStructure4Search(find.concat(matched))); } else { callback(); } @@ -110,6 +114,29 @@ BI.MultiLayerSelectTreeTrigger = BI.inherit(BI.Trigger, { }; }, + // 将搜索到的节点进行补充,构造成一棵完整的树 + _fillTreeStructure4Search: function (leaves) { + var result = BI.map(leaves, "id"); + var queue = leaves.reverse() || []; + while (BI.isNotEmptyArray(queue)) { + var node = queue.pop(); + var pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); + if (pNode != null) { + queue.push(pNode); + result.push(pNode.id); + } + } + var nodes = []; + BI.each(this.options.items, function (idx, item) { + if(BI.contains(result, item.id)) { + nodes.push(BI.extend({}, item, { + open: true + })) + } + }); + return nodes; + }, + _digest: function (v) { var o = this.options; return o.valueFormatter(v) || o.text; diff --git a/src/widget/multilayersingletree/multilayersingletree.combo.js b/src/widget/multilayersingletree/multilayersingletree.combo.js index f3b3c10d5f..4745c85a85 100644 --- a/src/widget/multilayersingletree/multilayersingletree.combo.js +++ b/src/widget/multilayersingletree/multilayersingletree.combo.js @@ -94,23 +94,9 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, { }; }, - _getSyncConfig: function () { - var o = this.options; - var baseConfig = this._getBaseConfig(); - baseConfig.el = { - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }; - return baseConfig; - }, - - _getAsyncConfig: function () { + _getSearchConfig: function() { var self = this, o = this.options; - var config = this._getBaseConfig(); - return BI.extend(config, { + return { el: { type: "bi.multilayer_single_tree_trigger", allowEdit: o.allowEdit, @@ -160,9 +146,28 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, { self.trigger.stopEditing(); } }] + } + }, + + _getSyncConfig: function () { + var o = this.options; + var baseConfig = this._getBaseConfig(); + return BI.extend(baseConfig, o.allowEdit ? this._getSearchConfig() : { + el: { + type: "bi.single_tree_trigger", + text: o.text, + height: o.height, + items: o.items, + value: o.value + } }); }, + _getAsyncConfig: function () { + var config = this._getBaseConfig(); + return BI.extend(config, this._getSearchConfig()); + }, + setValue: function (v) { v = BI.isArray(v) ? v : [v]; this.combo.setValue(v); diff --git a/src/widget/multilayersingletree/multilayersingletree.trigger.js b/src/widget/multilayersingletree/multilayersingletree.trigger.js index 46a2a219ff..08e855204e 100644 --- a/src/widget/multilayersingletree/multilayersingletree.trigger.js +++ b/src/widget/multilayersingletree/multilayersingletree.trigger.js @@ -14,6 +14,10 @@ BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { render: function () { var self = this, o = this.options; + if(o.itemsCreator === BI.emptyFn) { + this.tree = new BI.Tree(); + this.tree.initTree(BI.deepClone(BI.Tree.treeFormat(BI.deepClone(o.items)))); + } var content = { type: "bi.htape", items: [ @@ -68,7 +72,7 @@ BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { if(o.itemsCreator === BI.emptyFn) { var finding = BI.Func.getSearchResult(o.items, keyword); var matched = finding.match, find = finding.find; - callback(find.concat(matched)); + callback(self._fillTreeStructure4Search(find.concat(matched))); } else { callback(); } @@ -110,6 +114,29 @@ BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { }; }, + // 将搜索到的节点进行补充,构造成一棵完整的树 + _fillTreeStructure4Search: function (leaves) { + var result = BI.map(leaves, "id"); + var queue = leaves.reverse() || []; + while (BI.isNotEmptyArray(queue)) { + var node = queue.pop(); + var pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); + if (pNode != null) { + queue.push(pNode); + result.push(pNode.id); + } + } + var nodes = []; + BI.each(this.options.items, function (idx, item) { + if(BI.contains(result, item.id)) { + nodes.push(BI.extend({}, item, { + open: true + })) + } + }); + return nodes; + }, + _digest: function (v) { var o = this.options; return o.valueFormatter(v) || o.text;