now you need a tree menu (it needs to be automatically generated according to the data situation, not online, and in extreme cases, there are many level menus). Instead of using plug-ins, you need the following data format
[
{
name: "1",
children: [
{
name: "1-1",
children: [
{
name: "1-1-1"
}
]
}
]
},
{
name: "2",
children: [
{
name: "2-2"
}
]
},
{
name: "3"
}
]
// childrenchildren
the data format provided by the background is as follows
[
{
name: "",
children: {
"aaa":{
name: "aaa"
},
"bbb": {
name: "bbb",
children: {
"ccc": {
name: "ccc"
},
"ddd": {
name: "ddd"
}
}
}
}
},
{
name: "2",
children: {
"eee": {
name: "eee"
}
}
},
{
name: "3"
}
]
// ,childrenjsonkey,json{name: ""}
the semi-finished method written by yourself is as follows
var treeData = [];
function createdTreeData(data) {
data.forEach(function (item) {
function children(childrenData) {
var childrenArr = []
for (key in childrenData) {
// for in
}
return childrenArr
}
treeData.push({
name: item.name,
children: children(item.children)
})
})
}
// ps:ES6babel
wait online, thank you