简体   繁体   中英

how fix this extjs layout?

This is my ext code

Ext.create('Ext.panel.Panel', {
    title: 'Customer Information',
    width: 300,
    bodyPadding: 5,
    floating: true,
    renderTo: document.body,
    frame: true,
    collapsible: true,
    closable: true,
    defaults: { labelWidth: 90 },
    items: [{
                xtype: 'image',
                id: 'profile_pic',
                name: 'profile_pic',
                style: { display: 'block', margin: 'auto' },                
                src: 'http://www.sencha.com/img/20110215-feat-html5.png',               
        },{
            xtype: 'displayfield',
            fieldLabel: 'ID',
            name: 'viewer_id',
            id: 'viewer_id',
            padding: '5 0 0 0',
            fieldCls: 'specialfield',
            value: ''       
        },{
            xtype: 'displayfield',
            fieldLabel: 'Name',
            name: 'viewer_name',
            id: 'viewer_name',
            fieldCls: 'fieldcolor',
            value: '',
            width: 280
        },{
            xtype: 'displayfield',
            fieldLabel: 'Member ID',
            name: 'viewer_mem_id',
            id: 'viewer_mem_id',
            fieldCls: 'fieldcolor',
            width: 280          
        },{
            xtype: 'displayfield',
            fieldLabel: 'Address',
            name: 'viewer_address',
            id: 'viewer_address',
            fieldCls: 'fieldcolor',
            width: 280          
        },{
            xtype: 'displayfield',
            fieldLabel: 'Phone [Home]',
            name: 'viewer_phone_home',
            id: 'viewer_phone_home',
            fieldCls: 'fieldcolor',
            width: 280  

        },{
            xtype: 'displayfield',
            fieldLabel: 'Phone [Mobile]',
            name: 'viewer_phone_mobile',
            id: 'viewer_phone_mobile',
            fieldCls: 'fieldcolor',
            width: 280      
        },{
            xtype: 'displayfield',
            fieldLabel: 'Phone [Work]',
            name: 'viewer_phone_work',
            id: 'viewer_phone_work',
            fieldCls: 'fieldcolor',
            width: 280          
        }]
});

problem is first time it loads it shows like this

在此处输入图片说明

once the image loaded and then refresh it gives me the layout i needed

在此处输入图片说明

i guess the problem is happening due to image size. how to fix this issue?

sorry for the bad english

Regards

Found the correct way to do it by adding a listener and bind load event to element

var v_profile_image = Ext.widget('image', {
  src: '',
  style: { display: 'block', margin: 'auto' },
  name: 'profile_pic'
});

v_profile_image.on('load', function(e) {
  this.up('panel').doLayout();
}, v_profile_image, { element: 'el' });

From the comments above.

If the height of image is not changing you can set the height of image: height:90 inside the declaring the image: jsfiddle.net/6NK7n/

Anyway, the image will be resized to fit the height you set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM