How can I access class variables in an ExtJS event handler?

There are multiple ways to access the property getUrl Here are the few possible options.

There are multiple ways to access the property getUrl. Here are the few possible options: 1. Use Ext.

GetCmp: If you set an id for your FormPanel (or other extjs component whatever you are using), you can access it using Ext.getCmp() method. So, var yourComponent = Ext. GetCmp('yourComponentId'); alert(yourComponent.

GetUrl); 2. Use OwnerCt property: If you need to access your parent container (If the parent is holding your checkbox) you can access the parent container through the public property OwnerCt. 3.

Use refOwner property: If you use ref system in your code, you can make use of this property to get hold of the container and access the required variable. I think it will be easy for you to go with the first option.

Event handlers are usually called from a different scope (this value). If all you want is a single value in the handler, lexical scoping is the easiest way to go: var getUrl = 'test'; // now it's just a regular variable this.items" rel="nofollow">this.items. Add( new Ext.form.

Checkbox( { listeners: { check: function(checkbox, checked) { alert(getUrl); // still available - lexical scope! }, } ) ) Or if you really do want the parent object available as this in your event handler, you can use Ext.Function. Bind to modify the scope: this.

GetUrl='test'; this.items" rel="nofollow">this.items. Add( new Ext.form. Checkbox( { listeners: { check: Ext.Function.

Bind( function(checkbox, checked) { alert(this. GetUrl); }, this ), // second arg tells bind what to use for 'this' } ) ) Update: Ext.Function. Bind is an ExtJS 4 feature.

If you're on ExtJS 3. X or lower, you can use Function. CreateDelegate to the same end: this.

GetUrl='test'; this.items" rel="nofollow">this.items. Add( new Ext.form. Checkbox( { listeners: { check: function(checkbox, checked) { alert(this.

GetUrl); }. CreateDelegate(this) } ) ).

I wonder why nobody has suggested the obvious, just do it the Ext way and use the 'scope' config property: this. GetUrl = 'test'; this.items. Add( new Ext.form.

Checkbox( { listeners: { check: function(checkbox, checked) { alert(this. GetUrl); }, scope: this } ) ).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions