work needs to use a js recursive writing, really can not write it, ask for help, you can add Wechat to send a big red packet! The data structure of trustworthiness ~
is as follows:
[
{
key: "1",
name: "name",
label: "",
items: [
{
name: "name",
key: "1-1",
label: "",
items: [
{
name: "name",
key: "1-1-1",
label: "-0",
items: [
{
name: "name",
key: "1-1-1-1",
label: "-0-0",
items: "",
},
{
name: "name",
key: "1-1-1-2",
label: "-0-1",
items: "",
},
],
},
{
name: "name",
key: "1-1-2",
label: "-1",
items: "",
},
],
},
{
name: "name",
key: "1-2",
label: "",
items: [
{
name: "name",
key: "1-2-1",
label: "1",
items: "",
},
{
name: "name",
key: "1-2-2",
label: "2",
items: "",
},
],
},
{
name: "name",
key: "1-3",
label: "",
items: [
{
name: "name",
key: "1-3-1",
label: "1",
items: "",
},
{
name: "name",
key: "1-3-2",
label: "2",
items: "",
},
],
},
],
},
];
there may be countless levels of recursion. The requirement is that the "key" field in the data itself is not available, it should be generated in a loop, and the format of n-n-n should be generated hierarchically. So, a recursive function that passes in such a set of data returns data with the same structure and content, but with key with n-n-n.