Results 1 to 4 of 4

Thread: Very simple problem about Ext.getCmp()

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    3
    Vote Rating
    0
      0  

    Default Very simple problem about Ext.getCmp()

    Hi,
    I am a new-comer of Sencha Architect. I have coded a project using Notepad++ with Ext js. It works well. But then, I port that project to Sencha Architect and I am stuck with a very simple problem, Ext.getCmd().
    In this demo. I have only 1 button and 1 text field. When I click button, text field's text will change. But in Sencha Architect, I have this:
    Code:
    Ext.define('MyApp.view.MyContainer', {    extend: 'Ext.container.Container',
    
    
        height: 282,
        width: 436,
    
    
        initComponent: function() {
            var me = this;
    
    
            Ext.applyIf(me, {
                items: [
                    {
                        xtype: 'button',
                        text: 'MyButton',
                        listeners: {
                            click: {
                                fn: me.onButtonClick,
                                scope: me
                            }
                        }
                    },
                    {
                        xtype: 'textfield',
                        itemId: 'MyTextField',
                        value: 'DarkWing',
                        fieldLabel: 'Label'
                    }
                ]
            });
    
    
            me.callParent(arguments);
        },
    
    
        onButtonClick: function(button, e, options) {
            alert(Ext.getCmp("MyTextField"));
        }
    
    
    });
    Normally, it will alert [Object], but in this case. It just alerts Undefined.
    I wonder what's wrong?

  2. #2
    Sencha User filippo.ferrari's Avatar
    Join Date
    Apr 2010
    Location
    Sanremo - Italy
    Posts
    126
    Vote Rating
    1
      0  

    Default

    Ext.getCmp() <- get id of component if known; not recommended; use query and itemId

  3. #3
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,487
    Vote Rating
    145
      0  

    Default

    Change itemId to id.

    Ext.getCmp retrieves from the global ComponentManager. When you use an id, it will be registered with the global ComponentManager (note this means that you can only use an id once).

    For this reason, it is generally not recommended. If you want to use item id you could change Ext.getCmp to this.down('#MyTextField').

    By using itemId's you can create multiple instances of this object. itemId must be unique per container.
    Aaron Conran
    @aconran

  4. #4
    Sencha User
    Join Date
    Dec 2012
    Posts
    3
    Vote Rating
    0
      0  

    Default

    first give a id in Textfield
    {
    xtype: 'textfield',
    itemId: 'MyTextField',
    id:'text_id',
    value: 'DarkWing',
    fieldLabel: 'Label
    }
    onButtonClick: function(button, e, options) {
    alert(Ext.getCmp('text_id').setValue());

    I Think this is solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •