Browse Source

无JIRA任务 可配置children所在key

es6
windy 3 years ago
parent
commit
8c5854785a
  1. 11
      src/core/structure/tree.js

11
src/core/structure/tree.js

@ -387,17 +387,18 @@
};
BI.extend(BI.Tree, {
transformToArrayFormat: function (nodes, pId) {
transformToArrayFormat: function (nodes, pId, childKey) {
if (!nodes) return [];
var r = [];
childKey = childKey || "children";
if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]);
node.pId = node.pId == null ? pId : node.pId;
delete node.children;
r.push(node);
if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id));
if (nodes[i][childKey]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i][childKey], node.id));
}
}
} else {
@ -405,8 +406,8 @@
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children;
r.push(newNodes);
if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id));
if (nodes[childKey]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[childKey], newNodes.id));
}
}
return r;

Loading…
Cancel
Save