I have a JSON format that contains information about different people within various departments and sub-departments.
var personArray =
[
{name:"person1",code:"101011",mainDept:"mainD 1",dept:"dept1",SubDept:"Sub01"},
{name:"person2",code:"201012",mainDept:"mainD 1",dept:"dept1",SubDept:"Sub11"},
...
{name:"person29",code:"291119",mainDept:"mainD 5",dept:"dept161",SubDept:"Sub003"}];
I want to structure this data for use in jsTree, with multi-level grouping based on main department, department, sub-department, and individual persons.
Although I have managed to group the data by one level (mainDept), I am struggling to figure out how to achieve multi-level grouping as required.
var linq = Enumerable.From(personArray);
var grp = linq.GroupBy("$.mainDept","{text:$.dept}","{name:$,children:$$.ToArray()}").ToArray()