日期:2014-05-16  浏览次数:20391 次

[Ext4.2] 动态添加的Panel无法显示

有个 layout 为 border 的panel,它被分为上中下三个部分,分别在north、center、south

north里面有个按钮,点击它会调用aa(),aa()会往center添加一个panel。

但是点了之后,没看到效果。代码如下:


Ext.onReady(function(){Ext.create('Ext.panel.Panel', { 
width: 1024, 
height: 800, 
layout: 'border', 
id:'mainPanel',
items: [{
region:'north',
xtype:'form',
height:145,
layout: 'absolute',
margins: '0 3 3 3' ,
items:[{ x: 0, y: 0, xtype: 'button', text: '添加panel' , listeners: {
        click: {fn: function(){aa();}}
    }}]
     },{ 
        region: 'center', 
        xtype: 'panel', 
        layout: 'border', 
        margins: '0 3 3 3' ,
  id : 'centerPanel'
},{ 
region: 'south', 
xtype: 'panel', 
height: 100, 
margins: '0 3 3 3'
    }], 
renderTo: Ext.get('main-div') 
 });

function aa(){
var p = Ext.create('Ext.panel.Panel', {
    width: 200,
    height:200,
    html: '<p>Hello World!</p>'
});
p.render(Ext.get('centerPanel'),'center');
Ext.getCmp('centerPanel').doLayout();
Ext.getCmp('mainPanel').doLayout();
alert('aa end');
}});


------解决方案--------------------


        function aa() {
            var p = Ext.create('Ext.panel.Panel', {
                width: 200,
                height: 200,
                html: '<p>Hello World!</p>'
            });
            p.render(Ext.get('centerPanel').down('div'), 'center');//panel里面还会放置一个div用于显示内容,你要render到那个div里面,要不显示在父容器由于设置了overflow:hidden导致你这个新panel无法看到
        }