(curEl)
| 579 | }; |
| 580 | |
| 581 | let _getJsonPathKeys = function (curEl) { |
| 582 | let keys = []; |
| 583 | let current = curEl; |
| 584 | |
| 585 | // 处理当前节点 |
| 586 | if (current.hasClass('item') && !current.hasClass('rootItem')) { |
| 587 | if (current.hasClass('item-array-element')) { |
| 588 | // 这是数组元素,使用data-array-index属性 |
| 589 | let index = current.attr('data-array-index'); |
| 590 | if (index !== undefined) { |
| 591 | keys.unshift('[' + index + ']'); |
| 592 | } |
| 593 | } else { |
| 594 | // 这是对象属性,获取key |
| 595 | let keyText = current.find('>.key').text(); |
| 596 | if (keyText) { |
| 597 | keys.unshift(keyText); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | // 向上遍历所有祖先节点 |
| 603 | current.parents('.item').each(function() { |
| 604 | let $this = $(this); |
| 605 | |
| 606 | // 跳过根节点 |
| 607 | if ($this.hasClass('rootItem')) { |
| 608 | return false; // 终止遍历 |
| 609 | } |
| 610 | |
| 611 | if ($this.hasClass('item-array-element')) { |
| 612 | // 这是数组元素,使用data-array-index属性 |
| 613 | let index = $this.attr('data-array-index'); |
| 614 | if (index !== undefined) { |
| 615 | keys.unshift('[' + index + ']'); |
| 616 | } |
| 617 | } else if ($this.hasClass('item-object') || $this.hasClass('item-array')) { |
| 618 | // 这是容器节点,寻找它的key |
| 619 | let $container = $this.parent().parent(); // 跳过 .kv-list |
| 620 | if ($container.length && !$container.hasClass('rootItem')) { |
| 621 | if ($container.hasClass('item-array-element')) { |
| 622 | // 容器本身是数组元素 |
| 623 | let index = $container.attr('data-array-index'); |
| 624 | if (index !== undefined) { |
| 625 | keys.unshift('[' + index + ']'); |
| 626 | } |
| 627 | } else { |
| 628 | // 容器是对象属性 |
| 629 | let keyText = $container.find('>.key').text(); |
| 630 | if (keyText) { |
| 631 | keys.unshift(keyText); |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | } else { |
| 636 | // 普通item节点,获取key |
| 637 | let keyText = $this.find('>.key').text(); |
| 638 | if (keyText) { |
no test coverage detected