如何在加载页面时展开树面板 - EXTJS 4

时间:2013-02-28 17:52:28

标签: javascript ajax extjs extjs4

var tree = Ext.create('Ext.tree.Panel', {
        store: store,
        rootVisible: false,
        //useArrows: true,
        frame: true,
        title: 'Vehicle List',
        region:'west',
        width: 200,
        root: {
        expanded: true
        },
        checked : false,
        height: 250,
        dockedItems: [{
            xtype: 'toolbar',
            items: {
                text: 'Get checked nodes',
                handler: function(){
                    var records = tree.getView().getChecked(),
                        names = [];

                    Ext.Array.each(records, function(rec){
                        names.push(rec.get('MainID'));
                    });

                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    });
                }
            }
        }]
    });

如何让树扩展?我试过了

root: {
        expanded: true
        }

但它仍然不起作用。

2 个答案:

答案 0 :(得分:4)

将此添加到您的模型中:

{ name: 'expanded', type: 'boolean', defaultValue: true, persist: false },

或者,对于从服务器返回的每个节点,将expanded设置为true。

答案 1 :(得分:0)

root: {
        expanded: true
      }

这应该在您商店的定义范围内。

如下所示。

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
        children: [
            { text: "a", leaf: true },
            { text: "b", expanded: true, children: [
                { text: "c", leaf: true },
                { text: "d", leaf: true}
            ] }
        ]
    }
});