Search code examples
extjsextjs3

Grabbing a Extjs component


Please help understanding why the commented code below does not work on ExtJs 3.4:

var mywin=new Ext.Window({
        width : 200,
        height: 150,
        title : 'Accordion',
        layout: 'accordion',
        border: false,
        items: [
            panel1,
            panel2
        ]
    }).show();

    <!--Ext.getCmp('mywin').add({ - THIS DOES NOT WORK ,while below works-->

    mywin.add({
        title: 'Appended panel',
        id: 'addedPanel',
        html : 'Add Me!'
    });
    mywin.doLayout();

Solution

  • mywin is a reference to a window object that you created. This is just a normal JS construct using variable assignment.

    Ext.getCmp('mywin') attempts to look up a component that has an id property of mywin. It's typically a good idea to avoid using Ext.getCmp unless you'll only ever be creating once instance of the component, since it must be globally unique.