-
16 Jul 2012 9:54 AM #1
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' }] });
-
16 Jul 2012 12:31 PM #2
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.
-
16 Jul 2012 12:42 PM #3
Im not sure there is right answer. In my eyes fastest access is:
Items is Ext.util.AbstractMixedCollection, get function will return the item associated with the passed key OR index.Code:this.items.get('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.Code:Ext.getCmp('nameField')
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' })
-
19 Jul 2012 3:32 AM #4
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


Reply With Quote