I need some help… using Javascript I’m trying to create a parent-child relationship for lists and I’m not sure how to achieve this.
The objective is to have a structure depicted below:
ParentObject 1
- PO1 List item
- PO1 List item
- PO1 List item
- PO1 List item
ParentObject 2
- P02 List item
- P02 List item
- P02 List item
- P02 List item
…
I’m not looking for someone to code it out for me, I’m just looking for guidance from the community.
You can create an object with an array as a property.
So
You can then access the child elements with
parent.childlist[index]to get the child at the index position of the list. You can add a new item x to the list withparent.childlist.push(x)if you want to simplify creating this multiple times you can use a constructor, like this.