简体   繁体   English

如何在ExtJS 4.0.5中即时更改配置选项(minWidth)?

[英]How do I change config options (minWidth) on the fly in ExtJS 4.0.5?

I have an Ext.window.Window Component with minHeight and minWidth set in the config options like so: 我有一个Ext.window.Window组件,在配置选项中设置了minHeight和minWidth,如下所示:

config: {
         minWidth: 860,
         minHeight: 580
        },

Now I want to change these properties in a function like so: 现在,我想在像这样的函数中更改这些属性:

Ext.getCmp('x').setMinWidth(1280);

but that Setter doesn't exist in ExtJS 4.0.5 yet. 但是Extender 4.0.5中尚不存在该Setter。 (In later versions it does) (在更高版本中会)

I also tried doing this: 我也尝试这样做:

Ext.getCmp('x').config.minWidth = 1280;

but it also doesn't work. 但它也不起作用。

Thanks in advance. 提前致谢。

In ExtJS Window you can use updateLayout method after changing config value. 在ExtJS 窗口中 ,可以在更改配置值后使用updateLayout方法。

updateLayout updates this component's layout. updateLayout更新此组件的布局。 If this update effects this components ownerCt, that component's updateLayout method will be called to perform the layout instead. 如果此更新影响了此组件ownerCt,则将调用该组件的updateLayout方法来执行布局。 Otherwise, just this component (and its child items) will layout. 否则,将仅布局此组件(及其子项)。

Here I have created and sencha fiddle demo. 在这里,我创建了sencha小提琴演示。 It will show how is working, Hope this will help you to solve your problem or achieve your requirement. 它将显示工作方式,希望这将帮助您解决问题或达到您的要求。

Ext.create('Ext.window.Window', {
    title: 'Hello',
    minWidth: 400,
    minHeight: 300,
    layout: 'vbox',
    items: [{ // Let's put an empty grid in just to illustrate fit layout
        xtype: 'grid',
        flex: 1,
        width: '100%',
        border: false,
        store: {
            fields: ['name', 'email', 'phone'],
            data: {
                'items': [{
                    'name': 'Lisa',
                    "email": "lisa@simpsons.com",
                    "phone": "555-111-1224"
                }, {
                    'name': 'Bart',
                    "email": "bart@simpsons.com",
                    "phone": "555-222-1234"
                }, {
                    'name': 'Homer',
                    "email": "home@simpsons.com",
                    "phone": "555-222-1244"
                }, {
                    'name': 'Marge',
                    "email": "marge@simpsons.com",
                    "phone": "555-222-1254"
                }]
            },
            proxy: {
                type: 'memory',
                reader: {
                    type: 'json',
                    root: 'items'
                }
            }
        },
        columns: [{
            text: 'Name',
            dataIndex: 'name'
        }, {
            text: 'Email',
            dataIndex: 'email',
            flex: 1
        }, {
            text: 'Phone',
            dataIndex: 'phone'
        }],
    }, {
        xtype:'button',
        text: 'Update min height and width with Random Number',
        height: 40,
        margin: 10,
        width:'100%',
        renderTo: Ext.getBody(),
        handler: function () {
            /**
             * Returns a random integer between min (inclusive) and max (inclusive)
             * Using Math.round() will give you a non-uniform distribution!
             */
            function getRandomInt(min, max) {
                return Math.floor(Math.random() * (max - min + 1)) + min;
            }

            var num = getRandomInt(300, 600),
                wind = this.up('window');
            wind.minHeight = num;
            wind.minWidth = num;
            wind.updateLayout();
        }
    }]
}).show();

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

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