简体   繁体   English

Extjs动态添加图像不会调整容器面板的大小

[英]Extjs dynamically add image doesn't resize container panel

Here is the context: I've got a grid with some data, when i click on a button in an action column a window opens to display detailed information on the data. 这里是上下文:我有一个包含一些数据的网格,当我单击操作列中的按钮时,将打开一个窗口以显示有关数据的详细信息。 In this, window i dynamically add an image corresponding to the data. 在此,窗口i动态添加与数据相对应的图像。

The problem is that the panel containing the image doesn't re-size to fit image the first time I open the window , it works perfectly fine afterwards when the image is in the browser's cache 问题是包含图像的面板在我第一次打开窗口时不会调整大小以适合图像,此后当图像位于浏览器的缓存中时,它的工作原理就很好

I tried using the doLayout() or updateLayout() functions directly after adding the image or within a callback function on the panel.show() function. 我尝试在添加图像之后或在panel.show()函数的回调函数中直接使用doLayout()updateLayout() panel.show()函数。

I'm using a MVC architecture so all the functions are in different files (just for information) 我使用的是MVC体系结构,因此所有功能都位于不同的文件中(仅供参考)

Can anyone help me? 谁能帮我? I've been on this for several days... 我已经来这几天了...

Here's some code samples: 以下是一些代码示例:

the window constructor: 窗口构造函数:

constructor : function(params) {
    var rec=params.rec;
    config = this.config;
    config.title=rec.get('name');
    var mySQlId = rec.get('id');

    items=[ {
        xtype:'panel',
        autoScroll: true,
        border: false,
        header: false,
        layout: {
            type: 'vbox',
            pack: 'start',
            align: 'stretch',
        },
        items: [{
            xtype:'panel',  //this is where the image goes
            border: false,
            hidden:true,
        },
        {
            xtype: 'button',
            enableToggle: true,
            text: 'See 3D Structure',
            disabled:true,
        },{
            xtype:'gridMetaboliteIds',
            mysqlid: mySQlId
        }],
    }];

    config.items = items;

    this.callParent([config]);

}

the code that retrieves the image (in the controller script) 检索图像的代码(在控制器脚本中)

init : function() {
    this.control({
        'gridMetaboliteIds':{
            viewready:this.getImage             
        },
    });
},

getImage: function(grid){

    var store=grid.getStore();

    var panel=grid.up('panel');
    var imgPanel=panel.down('panel');
    var id=imgPanel.getId();


    var rec=store.findRecord('dbname','inchi');
    var bool=true;

    if (rec!=null){

        Ext.Ajax.request({
            url: 'sgetSVGFile.php', //This php get the name of the image coresponding to the data in a MySQL database
            params: {
                id: inchi
            },
            success: function(response){
                var json = Ext.JSON.decode(response.responseText, true);
                if (json[0]!=null){
                    var img=Ext.create('Ext.Img', {
                        src: 'resources/images/structure_metabolite/'+json[0]["svgFile"],
                        shrinkWrap:true,
                        border:false,

                    });
                    imgPanel.add(img);
                }
                else{
                    bool=false;
                }
            },
        })
        imgPanel.show(null, function(){
            imgPanel.doLayout();   // this is not working
        })


    }

    if (!bool){
        this.getGif(grid);  // if the svg image is not loaded do something else
    }
    //imgPanel.doLayout(); // this is not working either 

},

I finally manage to solve my problem, the error was coming from the panel in which i was adding the image. 我终于设法解决了我的问题,错误来自我添加图像的面板。

directly adding the image to the first panel (see below), and setting the layout to layout: 'auto' solved this issue. 直接将图像添加到第一个面板(请参见下文),然后将布局设置为layout: 'auto'解决了此问题。

items=[ {
        xtype:'panel',
        autoScroll: true,
        border: false,
        header: false,
        layout: 'auto',
        items: [Ext.create('Ext.Img', {
            src: 'resources/images/structure_metabolite/'+svgFile,

        }),
        {
            xtype: 'button',
            enableToggle: true,
            text: 'See 3D Structure',
            disabled:true,
            width:'100%'
        },{
            xtype:'gridMetaboliteIds',
            mysqlid: mySQlId
        }],
    }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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