extjs 树形菜单
时间: 2023-11-06 10:09:54 浏览: 45
ExtJS 是一个流行的 JavaScript 框架,提供了丰富的 UI 组件。要创建一个树形菜单,可以使用 Ext.tree.Panel 组件。
以下是一个简单的示例代码:
```
Ext.create('Ext.tree.Panel', {
title: 'Tree Panel',
width: 200,
height: 300,
store: Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{
text: 'Parent 1',
children: [
{ text: 'Child 1', leaf: true },
{ text: 'Child 2', leaf: true }
]
},
{
text: 'Parent 2',
children: [
{ text: 'Child 3', leaf: true },
{ text: 'Child 4', leaf: true }
]
}
]
}
}),
rootVisible: false
});
```
在这个例子中,我们创建了一个 Ext.tree.Panel 组件,并将其绑定到一个 Ext.data.TreeStore 数据源。数据源的根节点包含两个子节点,每个子节点又包含两个叶子节点。我们将 rootVisible 属性设置为 false,以隐藏根节点。
你可以根据自己的需要调整代码,添加更多节点和子节点,或者自定义菜单项的样式和行为。