Monday 26 March 2018

Traverse each nested object and create a div for each of them (EJS)

Using the following object, I need to create a HTML div element for each obj in that array using EJS.The div should look something like this:
Original comment
The replies of that original comment
The replies of the replies etc
Using the real info from the first object:
First updated comment
This is a reply to comment ID 1(the comment above)
reply to reply ID 5(the reply above)
(Of course if the "reply to reply" has a reply, it needs to be in that div too)The object itself: let obj = [ {"id":1,"comment":"First Updated Comment","parentID":null,"replies": [{"id":5,"comment":"This is a reply to comment ID 1","parentID":1,"replies": [{"id":9,"comment":"reply To reply ID 5","parentID":5,"replies":[]}]}]}, {"id":2,"comment":"Second Comment","parentID":null,"replies":[]}, {"id":3,"comment":"Third Comment","parentID":null,"replies":[]}, {"id":4,"comment":"4th Comment","parentID":null,"replies":[{"id":6,"comment":"Reply to Comment ID 4 ","parentID":4,"replies":[]}]}, {"id":7,"comment":"Testing BLACK ","parentID":null,"replies":[]}, {"id":8,"comment":"TriHard 7 comment id 7","parentID":null,"replies":[]} ] Thank you for your time.

Submitted March 26, 2018 at 05:41PM by khazha88

No comments:

Post a Comment