js多级菜单的数据结构
时间: 2023-11-26 19:43:24 浏览: 32
多级菜单的数据结构通常使用嵌套的对象或数组来表示。以下是两种常见的数据结构示例:
1. 使用对象表示多级菜单的数据结构:
```javascript
const menu = {
id: 1,
label: "菜单1",
children: [
{
id: 2,
label: "菜单1-1",
children: [
{
id: 3,
label: "菜单1-1-1",
children: []
},
{
id: 4,
label: "菜单1-1-2",
children: []
}
]
},
{
id: 5,
label: "菜单1-2",
children: []
}
]
};
```
2. 使用数组表示多级菜单的数据结构:
```javascript
const menu = [
{
id: 1,
label: "菜单1",
children: [
{
id: 2,
label: "菜单1-1",
children: [
{
id: 3,
label: "菜单1-1-1",
children: []
},
{
id: 4,
label: "菜单1-1-2",
children: []
}
]
},
{
id: 5,
label: "菜单1-2",
children: []
}
]
}
];
```
以上两种数据结构都可以根据实际需求进行扩展和修改,以适应不同的多级菜单结构。