简体   繁体   English

在EXT JS中显示窗口

[英]show the Window in EXT JS

var win,
        button = Ext.getCmp('show-btn');

    button.on('click', function(){
            win = Ext.define('MyApp.view.LeftRightWIndow', {
                extend: 'Ext.window.Window',

                height: 368,
                width: 546,
                title: 'My Window',

                initComponent: function() {
                    var me = this;

                    Ext.applyIf(me, {
                        items: [
                            {
                                xtype: 'container',
                                height: 193,
                                width: 515,
                                layout: {
                                    align: 'center',
                                    type: 'hbox'
                                },
                                items: [
                                    {
                                        xtype: 'container',
                                        flex: 1,
                                        margins: '',
                                        height: 135,
                                        padding: '10 10 10 10',
                                        width: 114,
                                        layout: {
                                            type: 'column'
                                        },
                                        items: [
                                            {
                                                xtype: 'textfield',
                                                padding: '0 0 10 0',
                                                width: 233,
                                                fieldLabel: 'Label'
                                            },
                                            {
                                                xtype: 'textfield',
                                                padding: '0 0 10 0',
                                                width: 233,
                                                fieldLabel: 'Label'
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'container',
                                        flex: 1,
                                        margins: '',
                                        height: 135,
                                        padding: '10 10 10 10',
                                        width: 114,
                                        layout: {
                                            type: 'column'
                                        },
                                        items: [
                                            {
                                                xtype: 'textfield',
                                                padding: '0 0 10 0',
                                                width: 233,
                                                fieldLabel: 'Label'
                                            },
                                            {
                                                xtype: 'textfield',
                                                padding: '0 0 10 0',
                                                width: 233,
                                                fieldLabel: 'Label'
                                            }
                                        ]
                                    }
                                ]
                            }
                        ],
                        dockedItems: [
                            {
                                xtype: 'toolbar',
                                dock: 'top',
                                items: [
                                    {
                                        xtype: 'tbtext',
                                        autoRender: true,
                                        cls: 'save',
                                        height: 26,
                                        padding: '5 5 5 5',
                                        width: 43,
                                        text: 'Save'
                                    },
                                    {
                                        xtype: 'tbseparator'
                                    },
                                    {
                                        xtype: 'tbtext',
                                        autoRender: true,
                                        cls: 'edit',
                                        height: 26,
                                        padding: '5 5 5 5',
                                        width: 43,
                                        text: 'Edit'
                                    }
                                ]
                            }
                        ]
                    });

                    me.callParent(arguments);
                }

            });
  });

how to show the Window when press the show-btn ? 按下show-btn时如何显示窗口?
this code im using Sencha Articheh to create. 此代码是使用Sencha Articheh创建的。 any idea? 任何想法?

With Ext.define() method you define class, but not creating instance of the class. 使用Ext.define()方法可以定义类,但不能创建该类的实例。 For creating class instance you have to use Ext.create() method. 为了创建类实例,您必须使用Ext.create()方法。

Also I recommend to move class definition outside click handler to separate file. 另外,我建议将类定义移至单击处理程序之外以分离文件。 If you are using standard application structure created by Sencha architect, create file with class definition in view folder. 如果使用的是Sencha architect创建的标准应用程序结构,请在视图文件夹中创建具有类定义的文件。

So in click handler you will have just: 因此,在点击处理程序中,您将只有:

// create instance of MyApp.view.LeftRightWIndow class
win = Ext.create('MyApp.view.LeftRightWIndow');
// display window
win.show();

On the present moment click event just create window object without displaying it. 目前,单击事件仅创建窗口对象而不显示它。 For showing your window after clicking on 'show-btn', you need just to invoke show() method of window object. 要在单击“ show-btn”后显示窗口,只需调用window对象的show()方法。 So try to place win.show() before last line, like this: 因此,尝试将win.show()放在最后一行之前,如下所示:

...
                me.callParent(arguments);
            }

        });
    win.show();
});

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

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