1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    17
    Vote Rating
    -1
    chaostimmy is an unknown quantity at this point

      0  

    Default what is the best way to access an item in a class?

    I have the following question (see the '??'):
    Code:
    Ext.define('MyClass', {
         extend: 'Ext.form.Panel',
         title: 'this is a form',
         setValidator: function (validator) {
                 ?? what is the best way to access the textfield here ??
                 Ext.getCmp("nameField").validator = validator;
                 ?? isn't a query for a component very slow ??
         },
         items: [{
               xtype: 'textfield',
               fieldLabel: 'put in your name here',
               itemId: 'nameField'
         }]
    });

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,388
    Vote Rating
    499
    scottmartin is a jewel in the rough scottmartin is a jewel in the rough scottmartin is a jewel in the rough scottmartin is a jewel in the rough

      1  

    Default

    Please refer to your other post of defining a class:
    http://www.sencha.com/forum/showthread.php?230723

    To access a variable in the same class you would use this.fieldname, but you would need to change your usages.

    Please have a look at the following article:
    http://www.sencha.com/learn/sencha-class-system/

    Regards,
    Scott.

  3. #3
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    747
    Vote Rating
    72
    Zdeno is just really nice Zdeno is just really nice Zdeno is just really nice Zdeno is just really nice

      1  

    Default

    Im not sure there is right answer. In my eyes fastest access is:

    Code:
    this.items.get('nameField'))
    Items is Ext.util.AbstractMixedCollection, get function will return the item associated with the passed key OR index.

    Code:
    Ext.getCmp('nameField')
    Ext.getCmp is more complex and there will be more records. Ext.getCmp use Ext.ComponentManager which extends Ext.AbstractManager. AbstractManager use Ext.util.HashMap to store all elements.

    As Scott wrote the best solution could be direct access to text field when you create it by:

    Code:
    this.nameField = Ext.create('Ext.form.field.Text', {
        fieldLabel: 'put in your name here',
        itemId: 'nameField'
    })

Thread Participants: 2

Tags for this Thread