将手风琴改为vbox只会渲染第一个子项

时间:2012-10-27 23:22:32

标签: javascript layout extjs extjs4

最初此面板具有accordion布局。然后显示两个儿童面板。但是一旦我将其更改为vbox,它就会显示第二个面板。但里面没有树!

查看图片。

enter image description here

相关代码

OurApp.online_tree_store = Ext.create('Ext.data.TreeStore', {
    root : {
        expanded : true,
        children : []
    }
});
OurApp.online_tree = Ext.create('Ext.tree.Panel', {
    store : OurApp.online_tree_store,
    title : 'Online',
    region: 'north',
    useArrows : true,
    rootVisible : false,
    listeners : {
        itemdblclick : contactitemdblclick
    }
});

/// Note: Offline tree is exactly the same as online tree.

Ext.create('Ext.panel.Panel', {
    closable : false,
    width : 300,
    maxWidth : 400,
    itemId : 'viewport-contacts',
    constrain : true,
    layout : 'accordion', // <--- layout changed to vbox or border
    region : 'west',
    hidden : true,
    border : true,
    defaults : {
        height : '50%', // <--- used for vbox
    },
    tbar : [{
        xtype : 'button',
        text : 'Sign out',
        iconCls : 'icon-disconnect',
        handler : function() {
        }
    }],
    items : [OurApp.online_tree, OurApp.offline_tree],
});

1 个答案:

答案 0 :(得分:2)

身高:'50%'应该是flex:1。

您还需要指定align:'stretch'

Ext.require('*');

Ext.onReady(function() {

    var panel = Ext.create('Ext.panel.Panel', {
        renderTo: document.body,
        width: 400,
        height: 400,
        layout: {
            type: 'vbox',
            align: 'stretch'
        },
        items: [{
            title: 'P1',
            flex: 1
        }, {
            title: 'P2',
            flex: 1
        }]
    });

});