如何在ExtJS事件处理程序中访问类变量? [英] How can I access class variables in an ExtJS event handler?

查看:94
本文介绍了如何在ExtJS事件处理程序中访问类变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  this.getUrl ='test'; 
this.items.add(
new Ext.form.Checkbox(
{
listeners:{
check:function(checkbox,checked){
alert(this.getUrl);
},
}


如何在支票处理程序中访问 this.getUrl

解决方案

有多种方法可以访问属性 getUrl 。以下是几个可能的选项:



1。使用Ext.getCmp :如果您为您的FormPanel(或其他extjs组件任何您正在使用)设置一个 id ,您可以使用 Ext.getCmp()方法。所以,

  var yourComponent = Ext.getCmp('yourComponentId'); 
alert(yourComponent.getUrl);

2。使用OwnerCt属性:如果您需要访问您的父容器(如果父级持有您的复选框),您可以通过公共属性 OwnerCt 访问父容器。



3。使用refOwner属性:如果您在代码中使用 ref 系统,则可以使用此属性来获取容器并访问所需的变量。 / p>

我认为使用第一个选项很容易。


this.getUrl = 'test';
this.items.add(
      new Ext.form.Checkbox(
            {
              listeners: {
                check: function(checkbox, checked) {
                  alert(this.getUrl);
                },
             }
       )
)

How do I access this.getUrl in the check handler?

解决方案

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.

这篇关于如何在ExtJS事件处理程序中访问类变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆