1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    12
    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?

    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
    7,185
    Vote Rating
    194
    scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold

      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
    326
    Vote Rating
    12
    Zdeno will become famous soon enough

      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'
    })

  4. #4
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    -2
    Nelson2100 has a little shameless behaviour in the past

      -1  

    Default


    I have no any major idea bout this to access the class any ways you just go to the Google and try there you can get the compatible answer from there

    Shop Fronts

Tags for this Thread