ExtJS动态treepanel存储负载以创建树菜单

时间:2019-01-10 14:23:04

标签: javascript extjs

它希望创建一个左侧菜单,当每个选项是商店的记录时,该菜单都可以折叠。

我已经尝试过您将在下面看到的代码,并尝试使用此example 我的代码什么也没产生

Ext.define('DashboardDigital.view.Viewport', {
    extend: 'Ext.container.Viewport',
    layout: 'border',

    items: [{
        region: 'west',
        id: 'tree-menu-main',
        collapsible: true,
        collapsed: false,
        width: 300,
        items: [{
            title: 'Menu',
            xtype: 'treepanel',
            useArrows: true,
            rootVisible: false,
            collapsible: true,
            collapsed: false,
            hideCollapseTool: true,
            listeners: {
                beforerender: function(tree) {
                    var ts = Ext.create('Ext.data.TreeStore');
                    ts.setRootNode({
                        root: true,
                        expanded: true,
                        children: Ext.getStore('sStatus').data.items
                    });
                    Ext.getCmp('tree-menu-main').setStore(ts);

                }
            },
        }]
    }, {
        xtype: 'component',
        id: 'testid',
        region: 'center',
        cls: 'treelist-log',
        padding: 10,
        height: 50,
        bind: {
            html: '{selectionText}'
        }
    }]
});

2 个答案:

答案 0 :(得分:0)

您正在将store设置为west组件: Ext.getCmp('tree-menu-main').setStore(ts);, 这是错误的。 您必须将id分配给菜单项并为其设置存储。

答案 1 :(得分:0)

这是一个适合您的示例:

Ext.define('Fiddle.view.main.Main', {
    extend: 'Ext.container.Container',

    layout: 'border',
    items: [ {
        region: 'center',
        title: 'Center region',
        bodyPadding: 12,
        html: 'center'
    }, {
        region: 'west',
        title: 'Menu',
        width: 200,
        collapsible: true,
        split: true,
        bodyPadding: 12,
        layout: 'anchor',
        items: [{
            xtype : 'treelist',
            store : new Ext.data.TreeStore({
                root: {
                    expanded: true,
                    children: [{
                        text: 'Home',
                        iconCls: 'x-fa fa-home',
                        children: [{
                            text: 'Messages',
                            iconCls: 'x-fa fa-inbox',
                            leaf: true
                        },{
                            text: 'Archive',
                            iconCls: 'x-fa fa-database',
                            children: [{
                                text: 'First',
                                iconCls: 'x-fa fa-sliders',
                                leaf: true
                            },{
                                text: 'No Icon',
                                iconCls: null,
                                leaf: true
                            }]
                        },{
                            text: 'Music',
                            iconCls: 'x-fa fa-music',
                            leaf: true
                        },{
                            text: 'Video',
                            iconCls: 'x-fa fa-film',
                            leaf: true
                        }]
                    },{
                        text: 'Users',
                        iconCls: 'x-fa fa-user',
                        children: [{
                            text: 'Tagged',
                            iconCls: 'x-fa fa-tag',
                            leaf: true
                        },{
                            text: 'Inactive',
                            iconCls: 'x-fa fa-trash',
                            leaf: true
                        }]
                    },{
                        text: 'Groups',
                        iconCls: 'x-fa fa-group',
                        leaf: true
                    },{
                        text: 'Settings',
                        iconCls: 'x-fa fa-wrench',
                        children: [{
                            text: 'Sharing',
                            iconCls: 'x-fa fa-share-alt',
                            leaf: true
                        },{
                            text: 'Notifications',
                            iconCls: 'x-fa fa-flag',
                            leaf: true
                        },{
                            text: 'Network',
                            iconCls: 'x-fa fa-signal',
                            leaf: true
                        }]
                    }]
                }
            })
        }]
    }]
});

Ext.application({

    name: 'Fiddle',
    mainView: 'Fiddle.view.main.Main',
    launch: function() {

    }
});