1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    3
    Vote Rating
    0
    darkwingbt is on a distinguished road

      0  

    Default Very simple problem about Ext.getCmp()

    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
    filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute filippo.ferrari has a reputation beyond repute

      0  

    Default


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

  3. #3
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,100
    Vote Rating
    113
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      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
    Sencha Architect Development Team

  4. #4
    Sencha User
    Join Date
    Dec 2012
    Posts
    3
    Vote Rating
    0
    nishant.chandwani is on a distinguished road

      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.