Results 1 to 3 of 3

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

  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    17
    Vote Rating
    -1
      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
      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
    763
    Vote Rating
    73
      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'
    })

Tags for this Thread

Posting Permissions

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