1 回答
TA贡献1845条经验 获得超8个赞
recur这是要打印的示例函数label。
const items = {
data: [
{
label: "Test-1",
data: "Test-1",
updated_at: "2020-3-23",
created_at: "2020-3-19",
expanded: true,
children: [
{
label: "Test-1.1",
data: "Test-1.1",
updated_at: "2020-3-19",
created_at: "2020-3-19",
expanded: true,
children: [
{
label: "Test-1.1.1",
updated_at: "2020-3-19",
created_at: "2020-3-19",
expanded: true,
children: [
{
label: "Test-1.1.1.1",
data: "Test-1.1.1.1",
updated_at: "2020-3-19",
created_at: "2020-3-19",
expanded: true
}
]
},
{
label: "Test-1.1.2",
data: "Test-1.1.2",
updated_at: "2020-3-19",
created_at: "2020-3-19",
expanded: true
},
{
label: "Test-1.1.3",
data: "Test-1.1.3",
updated_at: "2020-3-19",
created_at: "2020-3-19",
expanded: true
}
]
}
]
},
{
label: "Test-2",
data: "Test-2",
updated_at: "2020-3-19",
created_at: "2020-3-19",
expanded: true
}
]
};
const recur = arr => {
arr.forEach(item => {
console.log(item.label);
if (item.children) {
recur(item.children);
}
});
};
recur(items.data);
添加回答
举报