Browse Source

BI-49588 feat: 补充同步单选下拉树的搜索

es6
windy 5 years ago
parent
commit
a81e3248e1
  1. 37
      src/widget/multilayerselecttree/multilayerselecttree.combo.js
  2. 29
      src/widget/multilayerselecttree/multilayerselecttree.trigger.js
  3. 37
      src/widget/multilayersingletree/multilayersingletree.combo.js
  4. 29
      src/widget/multilayersingletree/multilayersingletree.trigger.js

37
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);

29
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;

37
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);

29
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;

Loading…
Cancel
Save