guy 8 years ago
parent
commit
1795bcbfac
  1. 18
      bi/base.js
  2. 59
      bi/core.js
  3. 42
      bi/widget.js
  4. 5
      demo/config.js
  5. 21
      demo/js/component/demo.treevaluechoosercombo.js
  6. 26
      demo/js/component/demo.treevaluechooserpane.js
  7. 6
      demo/js/component/demo.valuechooserpane.js
  8. 18
      docs/base.js
  9. 59
      docs/core.js
  10. 58
      docs/demo.js
  11. 42
      docs/widget.js
  12. 2
      src/base/tree/asynctree.js
  13. 2
      src/base/tree/parttree.js
  14. 14
      src/base/tree/treeview.js
  15. 40
      src/component/treevaluechooser/abstract.treevaluechooser.js
  16. 2
      src/component/valuechooser/pane.valuechooser.js
  17. 8
      src/core/base.js
  18. 51
      src/core/utils/tree.js

18
bi/base.js

@ -1710,7 +1710,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
_getNodeValue: function (node) {
//去除标红
return node.value || node.text.replace(/<[^>]+>/g, "");
return node.value == null ? node.text.replace(/<[^>]+>/g, "") : node.value;
},
//获取半选框值
@ -1802,6 +1802,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
var self = this, o = this.options;
var ns = BI.Tree.arrayFormat(nodes);
BI.each(ns, function (i, n) {
n.title = n.title || n.text || n.value;
//处理标红
if (BI.isKey(o.paras.keyword)) {
n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
@ -1944,7 +1945,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
},
setSelectedValue: function (value) {
this.options.paras.selectedValues = value || {};
this.options.paras.selectedValues = BI.deepClone(value) || {};
this.selectedValues = BI.deepClone(value) || {};
},
@ -1963,7 +1964,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
});
},
getExpandedValue: function(){
getExpandedValue: function () {
if (!this.nodes) {
return null;
}
@ -1980,14 +1981,9 @@ BI.TreeView = BI.inherit(BI.Pane, {
return this._getSelectedValues();
},
empty: function () {
BI.isNotNull(this.nodes) && this.nodes.destroy();
},
destroy: function () {
destroyed: function () {
this.stop();
this.nodes && this.nodes.destroy();
BI.TreeView.superclass.destroy.apply(this, arguments);
}
});
BI.extend(BI.TreeView, {
@ -2190,7 +2186,7 @@ BI.AsyncTree = BI.inherit(BI.TreeView, {
}
var checkedValues = this._getSelectedValues();
if (BI.isEmpty(checkedValues)) {
return this.selectedValues;
return BI.deepClone(this.selectedValues);
}
if (BI.isEmpty(this.selectedValues)) {
return checkedValues;
@ -2257,7 +2253,7 @@ BI.PartTree = BI.inherit(BI.AsyncTree, {
BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else {
o.itemsCreator(BI.extend({}, o.paras, {
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA,
type: BI.TreeView.REQ_TYPE_SELECT_DATA,
selectedValues: this.selectedValues,
notSelectedValue: name,
parentValues: parentValues

59
bi/core.js

@ -2352,15 +2352,15 @@ if (!window.BI) {
},
has: function (obj, keys) {
if (BI.isKey(keys)) {
return _.has.apply(_, arguments);
}
if (!keys || BI.isEmpty(keys)) {
if (BI.isArray(keys)) {
if (keys.length === 0) {
return false;
}
return BI.every(keys, function (i, key) {
return _.has(obj, key);
});
}
return _.has.apply(_, arguments);
},
//数字和字符串可以作为key
@ -9990,7 +9990,7 @@ $.extend(BI, {
},
isRoot: function (node) {
return node === this.root || node.id === this.root.id;
return node === this.root;
},
getRoot: function () {
@ -10367,7 +10367,7 @@ $.extend(BI, {
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]);
node.pId = pId;
node.pId = node.pId == null ? pId : node.pId;
delete node.children;
r.push(node);
if (nodes[i]["children"]) {
@ -10376,7 +10376,7 @@ $.extend(BI, {
}
} else {
var newNodes = BI.clone(nodes);
newNodes.pId = pId;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children;
r.push(newNodes);
if (nodes["children"]) {
@ -10387,21 +10387,25 @@ $.extend(BI, {
},
arrayFormat: function (nodes, pId) {
if (!nodes) return [];
if (!nodes) {
return [];
}
var r = [];
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = nodes[i];
node.pId = node.pId == null ? pId : node.pId;
r.push(node);
if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id));
r = r.concat(BI.Tree.arrayFormat(nodes[i]["children"], node.id));
}
}
} else {
var newNodes = nodes;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
r.push(newNodes);
if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id));
r = r.concat(BI.Tree.arrayFormat(nodes["children"], newNodes.id));
}
}
return r;
@ -10417,13 +10421,13 @@ $.extend(BI, {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if(BI.isNull(sNodes[i].id)) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = BI.clone(sNodes[i]);
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id != sNodes[i].pId) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
@ -10439,6 +10443,37 @@ $.extend(BI, {
}
},
treeFormat: function (sNodes) {
var i, l;
if (!sNodes) {
return [];
}
if (BI.isArray(sNodes)) {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = sNodes[i];
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
tmpMap[sNodes[i].pId].children.push(tmpMap[sNodes[i].id]);
} else {
r.push(tmpMap[sNodes[i].id]);
}
}
return r;
} else {
return [sNodes];
}
},
traversal: function (array, callback) {
if (BI.isNull(array)) {
return;

42
bi/widget.js

@ -17173,20 +17173,12 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
_initData: function (items) {
this.items = items;
var nodes = BI.Tree.transformToTreeFormat(items);
var nodes = BI.Tree.treeFormat(items);
this.tree = new BI.Tree();
this.tree.initTree(nodes);
this._initMap();
this._initFloors();
},
_initMap: function () {
var map = this.map = {};
BI.each(this.items, function (i, item) {
map[item.value] = item;
});
},
_initFloors: function () {
this.floors = -1;
var root = this.tree.getRoot();
@ -17258,7 +17250,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return;
}
BI.each(selected, function (k) {
var node = self._getNode(k);
var node = self._getNode(parentValues, k);
var newParents = BI.clone(parentValues);
newParents.push(node.value);
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents));
@ -17517,7 +17509,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
}
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) {
var node = self.map[value];
var node = self._getNode(parentValues, value)
result.push({
id: node.id,
pId: node.pId,
@ -17695,14 +17687,34 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return finded.finded.length > 0 || finded.matched.length > 0;
},
_getNode: function (v) {
return this.tree.search(v, "value");
_getNode: function (parentValues, v) {
var self = this;
var findedParentNode;
var index = 0;
this.tree.traverse(function (node) {
if (self.tree.isRoot(node)) {
return;
}
if (index > parentValues.length) {
return false;
}
if (index === parentValues.length && node.value === v) {
findedParentNode = node;
return false;
}
if (node.value === parentValues[index]) {
index++;
return;
}
return true;
});
return findedParentNode;
},
_getChildren: function (parentValues) {
if (parentValues.length > 0) {
var value = BI.last(parentValues);
var parent = this.tree.search(value, "value");
var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value);
} else {
var parent = this.tree.getRoot();
}
@ -17970,8 +17982,6 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, {
_defaultConfig: function () {
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-value-chooser-pane",
width: 200,
height: 30,
items: null,
itemsCreator: BI.emptyFn,
cache: true

5
demo/config.js

File diff suppressed because one or more lines are too long

21
demo/js/component/demo.treevaluechoosercombo.js

@ -4,29 +4,12 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, {
},
render: function () {
var tree = [];
for (var i = 0; i < 221; i++) {
tree.push({
value: "" + i + "",
text: "" + i + "",
id: i + "",
pId: null
});
for (var j = 0; j < 9; j++) {
tree.push({
value: i + "-" + j,
text: j + "",
id: i + "-" + j,
pId: i + ""
})
}
}
var widget = BI.createWidget({
type: "bi.tree_value_chooser_combo",
width: 300,
items: tree,
// items: BI.deepClone(Demo.CONSTANTS.TREEITEMS),
itemsCreator: function (op, callback) {
callback(tree);
callback(BI.deepClone(Demo.CONSTANTS.TREEITEMS));
}
});
return {

26
demo/js/component/demo.treevaluechooserpane.js

@ -4,30 +4,12 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, {
},
render: function () {
var tree = [];
for (var i = 0; i < 221; i++) {
tree.push({
value: "" + i + "",
text: "" + i + "",
id: i + "",
pId: null
});
for (var j = 0; j < 9; j++) {
tree.push({
value: i + "-" + j,
text: j + "",
id: i + "-" + j,
pId: i + ""
})
}
}
return {
type: "bi.tree_value_chooser_pane",
width: 300,
items: tree,
itemsCreator: function (op, callback) {
callback(tree);
}
items: BI.deepClone(Demo.CONSTANTS.TREEITEMS),
// itemsCreator: function (op, callback) {
// callback(tree);
// }
};
}
});

6
demo/js/component/demo.valuechooserpane.js

@ -6,9 +6,9 @@ Demo.ValueChooserPane = BI.inherit(BI.Widget, {
return {
type: "bi.value_chooser_pane",
items: BI.deepClone(Demo.CONSTANTS.ITEMS),
itemsCreator: function (op, callback) {
callback(BI.deepClone(Demo.CONSTANTS.ITEMS));
}
// itemsCreator: function (op, callback) {
// callback(BI.deepClone(Demo.CONSTANTS.ITEMS));
// }
};
}
});

18
docs/base.js

@ -1710,7 +1710,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
_getNodeValue: function (node) {
//去除标红
return node.value || node.text.replace(/<[^>]+>/g, "");
return node.value == null ? node.text.replace(/<[^>]+>/g, "") : node.value;
},
//获取半选框值
@ -1802,6 +1802,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
var self = this, o = this.options;
var ns = BI.Tree.arrayFormat(nodes);
BI.each(ns, function (i, n) {
n.title = n.title || n.text || n.value;
//处理标红
if (BI.isKey(o.paras.keyword)) {
n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
@ -1944,7 +1945,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
},
setSelectedValue: function (value) {
this.options.paras.selectedValues = value || {};
this.options.paras.selectedValues = BI.deepClone(value) || {};
this.selectedValues = BI.deepClone(value) || {};
},
@ -1963,7 +1964,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
});
},
getExpandedValue: function(){
getExpandedValue: function () {
if (!this.nodes) {
return null;
}
@ -1980,14 +1981,9 @@ BI.TreeView = BI.inherit(BI.Pane, {
return this._getSelectedValues();
},
empty: function () {
BI.isNotNull(this.nodes) && this.nodes.destroy();
},
destroy: function () {
destroyed: function () {
this.stop();
this.nodes && this.nodes.destroy();
BI.TreeView.superclass.destroy.apply(this, arguments);
}
});
BI.extend(BI.TreeView, {
@ -2190,7 +2186,7 @@ BI.AsyncTree = BI.inherit(BI.TreeView, {
}
var checkedValues = this._getSelectedValues();
if (BI.isEmpty(checkedValues)) {
return this.selectedValues;
return BI.deepClone(this.selectedValues);
}
if (BI.isEmpty(this.selectedValues)) {
return checkedValues;
@ -2257,7 +2253,7 @@ BI.PartTree = BI.inherit(BI.AsyncTree, {
BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else {
o.itemsCreator(BI.extend({}, o.paras, {
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA,
type: BI.TreeView.REQ_TYPE_SELECT_DATA,
selectedValues: this.selectedValues,
notSelectedValue: name,
parentValues: parentValues

59
docs/core.js

@ -13494,15 +13494,15 @@ if (!window.BI) {
},
has: function (obj, keys) {
if (BI.isKey(keys)) {
return _.has.apply(_, arguments);
}
if (!keys || BI.isEmpty(keys)) {
if (BI.isArray(keys)) {
if (keys.length === 0) {
return false;
}
return BI.every(keys, function (i, key) {
return _.has(obj, key);
});
}
return _.has.apply(_, arguments);
},
//数字和字符串可以作为key
@ -18448,7 +18448,7 @@ $.extend(BI, {
},
isRoot: function (node) {
return node === this.root || node.id === this.root.id;
return node === this.root;
},
getRoot: function () {
@ -18825,7 +18825,7 @@ $.extend(BI, {
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]);
node.pId = pId;
node.pId = node.pId == null ? pId : node.pId;
delete node.children;
r.push(node);
if (nodes[i]["children"]) {
@ -18834,7 +18834,7 @@ $.extend(BI, {
}
} else {
var newNodes = BI.clone(nodes);
newNodes.pId = pId;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children;
r.push(newNodes);
if (nodes["children"]) {
@ -18845,21 +18845,25 @@ $.extend(BI, {
},
arrayFormat: function (nodes, pId) {
if (!nodes) return [];
if (!nodes) {
return [];
}
var r = [];
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = nodes[i];
node.pId = node.pId == null ? pId : node.pId;
r.push(node);
if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id));
r = r.concat(BI.Tree.arrayFormat(nodes[i]["children"], node.id));
}
}
} else {
var newNodes = nodes;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
r.push(newNodes);
if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id));
r = r.concat(BI.Tree.arrayFormat(nodes["children"], newNodes.id));
}
}
return r;
@ -18875,13 +18879,13 @@ $.extend(BI, {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if(BI.isNull(sNodes[i].id)) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = BI.clone(sNodes[i]);
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id != sNodes[i].pId) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
@ -18897,6 +18901,37 @@ $.extend(BI, {
}
},
treeFormat: function (sNodes) {
var i, l;
if (!sNodes) {
return [];
}
if (BI.isArray(sNodes)) {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = sNodes[i];
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
tmpMap[sNodes[i].pId].children.push(tmpMap[sNodes[i].id]);
} else {
r.push(tmpMap[sNodes[i].id]);
}
}
return r;
} else {
return [sNodes];
}
},
traversal: function (array, callback) {
if (BI.isNull(array)) {
return;

58
docs/demo.js

File diff suppressed because one or more lines are too long

42
docs/widget.js

@ -17173,20 +17173,12 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
_initData: function (items) {
this.items = items;
var nodes = BI.Tree.transformToTreeFormat(items);
var nodes = BI.Tree.treeFormat(items);
this.tree = new BI.Tree();
this.tree.initTree(nodes);
this._initMap();
this._initFloors();
},
_initMap: function () {
var map = this.map = {};
BI.each(this.items, function (i, item) {
map[item.value] = item;
});
},
_initFloors: function () {
this.floors = -1;
var root = this.tree.getRoot();
@ -17258,7 +17250,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return;
}
BI.each(selected, function (k) {
var node = self._getNode(k);
var node = self._getNode(parentValues, k);
var newParents = BI.clone(parentValues);
newParents.push(node.value);
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents));
@ -17517,7 +17509,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
}
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) {
var node = self.map[value];
var node = self._getNode(parentValues, value)
result.push({
id: node.id,
pId: node.pId,
@ -17695,14 +17687,34 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return finded.finded.length > 0 || finded.matched.length > 0;
},
_getNode: function (v) {
return this.tree.search(v, "value");
_getNode: function (parentValues, v) {
var self = this;
var findedParentNode;
var index = 0;
this.tree.traverse(function (node) {
if (self.tree.isRoot(node)) {
return;
}
if (index > parentValues.length) {
return false;
}
if (index === parentValues.length && node.value === v) {
findedParentNode = node;
return false;
}
if (node.value === parentValues[index]) {
index++;
return;
}
return true;
});
return findedParentNode;
},
_getChildren: function (parentValues) {
if (parentValues.length > 0) {
var value = BI.last(parentValues);
var parent = this.tree.search(value, "value");
var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value);
} else {
var parent = this.tree.getRoot();
}
@ -17970,8 +17982,6 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, {
_defaultConfig: function () {
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-value-chooser-pane",
width: 200,
height: 30,
items: null,
itemsCreator: BI.emptyFn,
cache: true

2
src/base/tree/asynctree.js

@ -187,7 +187,7 @@ BI.AsyncTree = BI.inherit(BI.TreeView, {
}
var checkedValues = this._getSelectedValues();
if (BI.isEmpty(checkedValues)) {
return this.selectedValues;
return BI.deepClone(this.selectedValues);
}
if (BI.isEmpty(this.selectedValues)) {
return checkedValues;

2
src/base/tree/parttree.js

@ -46,7 +46,7 @@ BI.PartTree = BI.inherit(BI.AsyncTree, {
BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else {
o.itemsCreator(BI.extend({}, o.paras, {
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA,
type: BI.TreeView.REQ_TYPE_SELECT_DATA,
selectedValues: this.selectedValues,
notSelectedValue: name,
parentValues: parentValues

14
src/base/tree/treeview.js

@ -216,7 +216,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
_getNodeValue: function (node) {
//去除标红
return node.value || node.text.replace(/<[^>]+>/g, "");
return node.value == null ? node.text.replace(/<[^>]+>/g, "") : node.value;
},
//获取半选框值
@ -308,6 +308,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
var self = this, o = this.options;
var ns = BI.Tree.arrayFormat(nodes);
BI.each(ns, function (i, n) {
n.title = n.title || n.text || n.value;
//处理标红
if (BI.isKey(o.paras.keyword)) {
n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
@ -450,7 +451,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
},
setSelectedValue: function (value) {
this.options.paras.selectedValues = value || {};
this.options.paras.selectedValues = BI.deepClone(value) || {};
this.selectedValues = BI.deepClone(value) || {};
},
@ -469,7 +470,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
});
},
getExpandedValue: function(){
getExpandedValue: function () {
if (!this.nodes) {
return null;
}
@ -486,14 +487,9 @@ BI.TreeView = BI.inherit(BI.Pane, {
return this._getSelectedValues();
},
empty: function () {
BI.isNotNull(this.nodes) && this.nodes.destroy();
},
destroy: function () {
destroyed: function () {
this.stop();
this.nodes && this.nodes.destroy();
BI.TreeView.superclass.destroy.apply(this, arguments);
}
});
BI.extend(BI.TreeView, {

40
src/component/treevaluechooser/abstract.treevaluechooser.js

@ -13,20 +13,12 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
_initData: function (items) {
this.items = items;
var nodes = BI.Tree.transformToTreeFormat(items);
var nodes = BI.Tree.treeFormat(items);
this.tree = new BI.Tree();
this.tree.initTree(nodes);
this._initMap();
this._initFloors();
},
_initMap: function () {
var map = this.map = {};
BI.each(this.items, function (i, item) {
map[item.value] = item;
});
},
_initFloors: function () {
this.floors = -1;
var root = this.tree.getRoot();
@ -98,7 +90,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return;
}
BI.each(selected, function (k) {
var node = self._getNode(k);
var node = self._getNode(parentValues, k);
var newParents = BI.clone(parentValues);
newParents.push(node.value);
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents));
@ -357,7 +349,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
}
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) {
var node = self.map[value];
var node = self._getNode(parentValues, value)
result.push({
id: node.id,
pId: node.pId,
@ -535,14 +527,34 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return finded.finded.length > 0 || finded.matched.length > 0;
},
_getNode: function (v) {
return this.tree.search(v, "value");
_getNode: function (parentValues, v) {
var self = this;
var findedParentNode;
var index = 0;
this.tree.traverse(function (node) {
if (self.tree.isRoot(node)) {
return;
}
if (index > parentValues.length) {
return false;
}
if (index === parentValues.length && node.value === v) {
findedParentNode = node;
return false;
}
if (node.value === parentValues[index]) {
index++;
return;
}
return true;
});
return findedParentNode;
},
_getChildren: function (parentValues) {
if (parentValues.length > 0) {
var value = BI.last(parentValues);
var parent = this.tree.search(value, "value");
var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value);
} else {
var parent = this.tree.getRoot();
}

2
src/component/valuechooser/pane.valuechooser.js

@ -11,8 +11,6 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, {
_defaultConfig: function () {
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-value-chooser-pane",
width: 200,
height: 30,
items: null,
itemsCreator: BI.emptyFn,
cache: true

8
src/core/base.js

@ -457,15 +457,15 @@ if (!window.BI) {
},
has: function (obj, keys) {
if (BI.isKey(keys)) {
return _.has.apply(_, arguments);
}
if (!keys || BI.isEmpty(keys)) {
if (BI.isArray(keys)) {
if (keys.length === 0) {
return false;
}
return BI.every(keys, function (i, key) {
return _.has(obj, key);
});
}
return _.has.apply(_, arguments);
},
//数字和字符串可以作为key

51
src/core/utils/tree.js

@ -17,7 +17,7 @@
},
isRoot: function (node) {
return node === this.root || node.id === this.root.id;
return node === this.root;
},
getRoot: function () {
@ -394,7 +394,7 @@
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]);
node.pId = pId;
node.pId = node.pId == null ? pId : node.pId;
delete node.children;
r.push(node);
if (nodes[i]["children"]) {
@ -403,7 +403,7 @@
}
} else {
var newNodes = BI.clone(nodes);
newNodes.pId = pId;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children;
r.push(newNodes);
if (nodes["children"]) {
@ -414,21 +414,25 @@
},
arrayFormat: function (nodes, pId) {
if (!nodes) return [];
if (!nodes) {
return [];
}
var r = [];
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = nodes[i];
node.pId = node.pId == null ? pId : node.pId;
r.push(node);
if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id));
r = r.concat(BI.Tree.arrayFormat(nodes[i]["children"], node.id));
}
}
} else {
var newNodes = nodes;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
r.push(newNodes);
if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id));
r = r.concat(BI.Tree.arrayFormat(nodes["children"], newNodes.id));
}
}
return r;
@ -444,13 +448,13 @@
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if(BI.isNull(sNodes[i].id)) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = BI.clone(sNodes[i]);
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id != sNodes[i].pId) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
@ -466,6 +470,37 @@
}
},
treeFormat: function (sNodes) {
var i, l;
if (!sNodes) {
return [];
}
if (BI.isArray(sNodes)) {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = sNodes[i];
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
tmpMap[sNodes[i].pId].children.push(tmpMap[sNodes[i].id]);
} else {
r.push(tmpMap[sNodes[i].id]);
}
}
return r;
} else {
return [sNodes];
}
},
traversal: function (array, callback) {
if (BI.isNull(array)) {
return;

Loading…
Cancel
Save