Ext JS 4.1中的递归树菜单结构

时间:2012-09-22 01:38:29

标签: javascript menu extjs

首先,我是ExtJS的新人。我希望你的帮助让我知道获取树状菜单的最佳方法,其中包含n个递归项。 例如:

FOLDER

.. FOLDER

... ITEM

... FOLDER

...... ITEM

...... ITEM

... FOLDER

...

我遵循Sencha提出的最佳做法。我能够用一个级别做一个树状菜单,但是当尝试为n级别做它时,它失败了(事实上,应用程序工作但显示第一级的无限节点)。显然问题是我的菜单项的模型定义,请参阅:

Ext.define('Dashboard.model.MenuItem',{
extend: 'Dashboard.model.AbstractMenuElement',

  fields:
  [
        {name: 'content', type: 'string'},
        {name: 'skeletonFlag', type: 'string'},
        {name: 'fatherId', type: 'int'} 
  ],


  associations:
  [
    {type: 'hasMany', model: 'Dashboard.model.MenuItem', name: 'children', mapping: 'items'}
  ]

});

因此该模型递归地创建无限节点。但是......你知道我应该如何建模菜单项以实现递归菜单吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

要在Ext JS中显示树状结构,我认为最好的办法是将Ext.model.TreeModelExt.model.TreeStoreExt.tree.Panel结合使用。

这是一个简单的示例,用于匹配您在问题中提到的结构:

Ext.create('Ext.tree.Panel', {
    store: Ext.create('Ext.data.TreeStore', {
        root: {
            text: 'Root Folder',
            expanded: true,
            children: [
                {text: 'Folder 1', children: [
                    {text: 'Item 1', leaf: true}
                ]},
                {text: 'Folder 2', expanded: true, children: [
                    {text: 'Item 2', leaf: true},
                    {text: 'Item 3', leaf: true}
                ]},
                {text: 'Folder 3', children: []}
            ]
        }
    }),
    renderTo: Ext.getBody()
});

您可以在Plunker上查看this example

相关问题