Are you seeking this information?
$(document).ready(function() {
var treeJson = {
"values": [{
"tree_title": "FashionWorld1",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel11",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel21"
},
{
"tree_title": "SubmenuLevel22"
},
{
"tree_title": "SubmenuLevel23"
}
]
}]
},
{
"tree_title": "SubmenuLevel12"
},
{
"tree_title": "SubmenuLevel13"
}
]
}]
},
{
"tree_title": "FashionWorld2",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel11",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel21"
},
{
"tree_title": "SubmenuLevel22"
},
{
"tree_title": "SubmenuLevel23"
}
]
}]
},
{
"tree_title": "SubmenuLevel12"
},
{
"tree_title": "SubmenuLevel13"
}
]
}]
},
{
"tree_title": "FashionWorld3",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel11",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel21"
},
{
"tree_title": "SubmenuLevel22"
},
{
"tree_title": "SubmenuLevel23"
}
]
}]
},
{
"tree_title": "SubmenuLevel12"
},
{
"tree_title": "SubmenuLevel13"
}
]
}]
},
{
"tree_title": "FashionWorld4",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel11",
"tree_image": "img_arrow",
"tree_image_position": "1",
"tree_image": "FashionWorld",
"isopen": "0",
"child": [{
"values": [{
"tree_title": "SubmenuLevel21"
},
{
"tree_title": "SubmenuLevel22"
},
{
"tree_title": "SubmenuLevel23"
}
]
}]
},
{
"tree_title": "SubmenuLevel12"
},
{
"tree_title": "SubmenuLevel13"
}
]
}]
}
]
};
var treeParentArr = treeJson.values;
var tree = buildNodes(treeJson, $("#tree"));
});
function buildNodes(node, parent) {
$(node.values).each(function() {
var element = this;
var listItem = $("<li />", {
text: this.tree_title
})
if (this.hasOwnProperty("child")) {
var tree = $("<ul />");
buildNodes(this.child[0], tree);
listItem.append(tree)
}
parent.append(listItem);
});
}
JSFiddle
Just wondering, why have the nested values
inside child
when it's an Array and could be named something like childs
for the values objects?