'jquery match subtask to parent task by ID

I am trying to work through the logic of joining two SharePoint 2013 lists with jquery. The parent list is Tasks with system-generated ID. The child list is SubTasks with system-generated ID and a set ParentID (I'm in the prototype phase, so I have versions that the ParentID field is a lookup to the Task list and one where it is just a text field). I am doing a jsom call to each list.

The output should be a div class for the Task and a nested div class for the subtask. I am using HTML/CSS to make tiles for the tasks and trying to have a tile expansion below it with the subtasks.

I thought about processing the task data and formatting it, then processing the child task data. Then do a comparison of the ID fields to find matches. I'm expecting a lot of data and this seems excessive comparison.

The other approach was during the formatting of the parent task, during the while taskCollection.moveNext() function, processing the childtasks if parentID = ID. This seems more streamlined and should ensure the children stay with the parent.

Not sure how to pass in both jsom data sets from the separate calls, then iterate over them.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source