This particular element is found within my Vue2 application:
<div class="child-elements-container draggable-container">
<div>
<div entity-type="entitytype1" type="elementType" id="2" class="single-element"></div>
<div class="child-elements-container draggable-container">
<div>
<div entity-type="entitytype2" type="elementType" id="59" class="single-element"></div>
</div>
</div>
</div>
<div>
<div entity-type="measures" type="elementType" id="3" class="single-element"></div>
<div class="child-elements-container draggable-container">
<div>
<div entity-type="entitytype3" type="elementType" id="13" class="single-element"></div>
<div class="child-elements-container draggable-container"></div>
</div>
<div>
<div entity-type="entitytype2" type="elementType" id="14" class="single-element"></div>
<div class="child-elements-container draggable-container"></div>
</div>
</div>
</div>
<div>
<div entity-type="entitytype3" type="elementType" id="11" class="single-element">
</div>
<div class="child-elements-container draggable-container">
<div>
<div entity-type="entitytype3" type="elementType" id="12" class="single-element">
</div>
<div class="child-elements-container draggable-container"></div>
</div>
</div>
</div>
</div>
The main goal is to obtain a tree structure utilizing the IDs of single-elements, and I am utilizing this function to visualize the hierarchy:
buildDraggedHierarchy(el) {
if (!el) {
return [];
}
const children = [...el.querySelectorAll(":scope>div")];
const output = children.map((child) => ({
id: child.querySelector(".single-element") ? child.querySelector(".plan-element").id : null,
type: child.getAttribute("type"),
children: this.buildDraggedHierarchy(child.querySelector(".draggable-container")),
}));
return output;
},
However, the current output is as follows:
[
{
"id": "2",
"type": null,
"children": [
{
"id": "59",
"type": null,
"children": []
}
]
},
{
"id": "3",
"type": null,
"children": [
{
"id": "13",
"type": null,
"children": []
},
{
"id": "14",
"type": null,
"children": []
}
]
},
{
"id": "11",
"type": null,
"children": [
{
"type": null,
"children": []
}
]
}
]
It seems that the last element's children are not displayed correctly. It should include an ID of 12, but it is missing entirely. How can I resolve this issue?