Учитывая эти 4 переменные,
var el1 = {name:'ronaldo', team: 'europe/spain/realmadrid'}
var el2 = {name:'messi', team: 'europe/spain/barcelona'}
var el3 = {name:'gerald', team: 'europe/england/liverpool'}
var el4 = {name:'unknown english', team: 'europe/england'}
Мне нужно создать эту иерархию дерева JSON,
{
"text":"europe",
"leaf":false,
"children":[
{
"text":"spain",
"leaf":false,
"children":[
{
"text":"realmadrid",
"leaf":false,
"children":[
{
"text":"ronaldo",
"leaf":true
}
]
},
{
"text":"barcelona",
"leaf":false,
"children":[
{
"text":"messi",
"leaf":true
}
]
}
]
},
{
"text":"england",
"leaf":false,
"children":[
{
"text":"unknown english",
"leaf":true
},
{
"text":"liverpool",
"leaf":false,
"children":[
{
"text":"gerald",
"leaf":true
}
]
}
]
}
]
}