如何获取组件名称的对象? [英] How to get object of component by its name?

查看:140
本文介绍了如何获取组件名称的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图:

tbar: [
        {
            iconCls:'icon-p',
            hidden: true,
            name:'p',
            handler:'onPClick'
        },
        {
            xtype: 'tbfill'
        },
        {
            iconCls:'icon-n',
            hidden:true,
            name: 'n',
            handler:'onNClick'
        }
    ],

    initComponent:  function(){
      Ext.apply(this, {
        layout: 'fit',  
        items: [
          {
            xtype:'textareafield',
            name: 'name_content'  
          }
        ]
      });
      this.callParent();
    }

OnPClick我正在做form.up('id')。getForm()

OnPClick I am doing form.up('id').getForm().

如何通过名称获取图标的对象,显示我可以隐藏或显示该图标。

How to get Object of icon-p by its name show that I can hide or show that icon.

推荐答案

在onPClick处理程序中,您可以获得第一个参数中组件的引用。

您的控制器中有一些处理函数

In the onPClick handler you get the reference to the component in the first parameter.
Somewhere in your controller you have the handler function

onPClick : function(icon-p-object){
  // do some stuff with the icon-p-object
}

当您将 itemId 分配给您的 icon-n对象,那么您可以轻松获取参考,当
在您的onPClick处理程序中执行以下操作时:

When you assign an itemId to your icon-n object, then you can easily get the reference, when you do the follwoing in your onPClick handler

var parentComponent = icon-p-object.up(); // now we have the reference to the parent container
var icon-n-Component = parentComponent.down('#icon-n'); // and with that we can get the other reference of the child element

完整的代码应该是

onPClick : function(icon-p-object){
  var parentComponent = icon-p-object.up();
  var icon-n-Component = parentComponent.down('#icon-n');
  // do some stuff with the icon-n object
}

这篇关于如何获取组件名称的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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