I am struggling from past two days to write a efficient algorithm from the json data to create the source object for jqxtree. The data I receive is in this form
var data = [
{
number: 1001,
title: "Toyota : Corolla : LE : 2014"
}, {
number: 1002,
title: "Toyota : Corolla : Sports : 2015"
}, {
number: 1003,
title: "Toyota : Corolla : LE : 2013"
}, {
number: 1004,
title: "Toyota : Camry: LE : 2013"
}]
Now I need to create a source object as
var source = [
{ label: "Toyota",
items: [
{ label: "Corolla",
items : [{ label : "LE"
items : [{label : 2014}
{label : 2013}]},
{ label : "Sports"
items : [{label : 2015}]} ]},
{ label: "Camry",
items : [{ label : "LE"
items : {label : 2013}}]}
]
}
];
Can anyone please help me with this.
Thanks