I have a list template like this
list = [
{
id: "G1",
text: "Group 1",
idparent: "",
children: [
{
start: "2014-10-01",
end: "2014-10-03",
id: "1",
text: "Task 1"
idparent: "G1",
},
{
start: "2014-10-03",
end: "2014-10-05",
id: "2",
text: "Task 2"
idparent: "G1",
}
]
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "3",
text: "Task 3"
idparent: "",
},
];
The first item with children is a group of items and the last one is a single item. And the list to be treated is the following
list_to_tree = [
{
start: "2014-10-01",
end: "2014-10-03",
id: "G1",
text: "Group 1"
id_parent: ""
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "1",
text: "Task 1"
id_parent: "G1"
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "2",
text: "Task 2",
id_parent: "G1"
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "3",
text: "Task 3"
id_parent: ""
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "G2",
text: "Group 2"
id_parent: "G1"
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "4",
text: "Task 4",
id_parent: "G2"
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "5",
text: "Task 5",
id_parent: ""
},
{
start: "2014-10-01",
end: "2014-10-03",
id: "G3",
text: "Group 3",
id_parent: ""
},
];
How to sort this list so that it can look like the model above knowing that we can have an infinite number(n) of child spots (group or item). Eg: Task -> subtasks -> n(substasks) if have