|
1446 | 1446 | $hierarchy.append($nodesLayer); |
1447 | 1447 | } |
1448 | 1448 | // recurse through children nodes |
1449 | | - $.each(data.children, function () { |
1450 | | - if (Array.isArray(this)) { |
| 1449 | + $.each(data, function () { |
| 1450 | + if (Array.isArray(this)) { // 处理一对夫妻(可能有多个妻) |
1451 | 1451 | $.each(this, function() { |
1452 | 1452 | this.level = level + 1; |
1453 | | - if (data.compact) { |
1454 | | - that.buildHierarchy($nodeDiv, this); |
1455 | | - } else { |
1456 | | - var $nodeCell = $('<li class="hierarchy">'); |
1457 | | - $nodesLayer.append($nodeCell); |
1458 | | - that.buildHierarchy($nodeCell, this); |
1459 | | - } |
1460 | 1453 | }); |
| 1454 | + that.buildHierarchy($nodesLayer, [this]); |
1461 | 1455 | } else { |
1462 | 1456 | this.level = level + 1; |
1463 | | - if (data.compact) { |
| 1457 | + if (this.compact) { |
1464 | 1458 | that.buildHierarchy($nodeDiv, this); |
1465 | 1459 | } else { |
1466 | 1460 | var $nodeCell = $('<li class="hierarchy">'); |
|
1491 | 1485 | } |
1492 | 1486 | } |
1493 | 1487 | // Construct the single node in OrgChart or the multiple nodes in family tree |
1494 | | - if (Array.isArray(data)) { |
1495 | | - $.each(data, function () { |
| 1488 | + if (Array.isArray(data)) { // 处理family tree的情况 |
| 1489 | + $.each(data, function () { // 构造一个家庭的hierarchy |
1496 | 1490 | var _this = this; |
1497 | | - $.each(this, function (i) { |
| 1491 | + $.each(this, function (i) { // 构造一个夫/妻节点 |
1498 | 1492 | $nodeDiv = that.createNode(this); |
1499 | 1493 | // if there are only two persons in a marriage, two single nodes will appear in a hierarchy |
1500 | 1494 | if (_this.length === 2 && i === 1) { |
1501 | | - $hierarchy.children('.hierarchy:first').append($nodeDiv); |
| 1495 | + $hierarchy.find(`#${_this[0].id}`).after($nodeDiv); |
1502 | 1496 | if (this.children && this.children.length) { |
1503 | | - that.buildInferiorNodes($hierarchy.children('.hierarchy:first'), $nodeDiv, this, level); |
| 1497 | + that.buildInferiorNodes($hierarchy.find(`#${_this[0].id}`).parent(), $nodeDiv, this.children, level); |
1504 | 1498 | } |
1505 | 1499 | } else { |
1506 | 1500 | // if there are more than two persons in a marriage, every node will be included in a single hierarchy |
1507 | 1501 | var $wrapper = $('<li class="hierarchy"></li>'); |
1508 | 1502 | $wrapper.append($nodeDiv); |
1509 | 1503 | $hierarchy.append($wrapper); |
1510 | 1504 | if (this.children && this.children.length) { |
1511 | | - that.buildInferiorNodes($wrapper, $nodeDiv, this, level); |
| 1505 | + that.buildInferiorNodes($wrapper, $nodeDiv, this.children, level); |
1512 | 1506 | } |
1513 | 1507 | } |
1514 | 1508 | }); |
|
1517 | 1511 | $nodeDiv = this.createNode(data); |
1518 | 1512 | $hierarchy.append($nodeDiv); |
1519 | 1513 | if (data.children && data.children.length) { |
1520 | | - this.buildInferiorNodes($hierarchy, $nodeDiv, data, level); |
| 1514 | + this.buildInferiorNodes($hierarchy, $nodeDiv, data.children, level); |
1521 | 1515 | } |
1522 | 1516 | } |
1523 | | - |
1524 | | - // Construct the "inferior nodes" |
1525 | | - /*if (data.children && data.children.length) { |
1526 | | - var isHidden = level + 1 > opts.visibleLevel || (data.collapsed !== undefined && data.collapsed); |
1527 | | - var $nodesLayer; |
1528 | | - if ((opts.verticalLevel && (level + 1) >= opts.verticalLevel) || data.hybrid) { |
1529 | | - $nodesLayer = $('<ul class="nodes">'); |
1530 | | - if (isHidden && (opts.verticalLevel && (level + 1) >= opts.verticalLevel)) { |
1531 | | - $nodesLayer.addClass('hidden'); |
1532 | | - } |
1533 | | - if (((opts.verticalLevel && level + 1 === opts.verticalLevel) || data.hybrid) |
1534 | | - && !$hierarchy.closest('.vertical').length) { |
1535 | | - $nodesLayer.addClass('vertical'); |
1536 | | - } |
1537 | | - $hierarchy.append($nodesLayer); |
1538 | | - } else if (data.compact) { |
1539 | | - $nodeDiv.addClass('compact'); |
1540 | | - } else { |
1541 | | - $nodesLayer = $('<ul class="nodes' + (isHidden ? ' hidden' : '') + '">'); |
1542 | | - if (isHidden) { |
1543 | | - $hierarchy.addClass('isChildrenCollapsed'); |
1544 | | - } |
1545 | | - $hierarchy.append($nodesLayer); |
1546 | | - } |
1547 | | - // recurse through children nodes |
1548 | | - $.each(data.children, function () { |
1549 | | - this.level = level + 1; |
1550 | | - if (data.compact) { |
1551 | | - that.buildHierarchy($nodeDiv, this); |
1552 | | - } else { |
1553 | | - var $nodeCell = $('<li class="hierarchy">'); |
1554 | | - $nodesLayer.append($nodeCell); |
1555 | | - that.buildHierarchy($nodeCell, this); |
1556 | | - } |
1557 | | - }); |
1558 | | - }*/ |
1559 | 1517 | }, |
1560 | 1518 | // build the child nodes of specific node |
1561 | 1519 | buildChildNode: function ($appendTo, data) { |
|
0 commit comments