如何通过名称获取组件对象?

时间:2014-12-01 14:47:15

标签: extjs

我正在使用formPanel,如:

tbar: [
        {
            iconCls:'icon-previous',
            hidden: true,
            //id:'previous',
            name:'previous',
            handler:'onPClick'
        },
        {
            xtype: 'tbfill'
        },
        {
            iconCls:'icon-next',
            hidden:true,
            //id: 'next',
            name: 'next',
            handler:'onNClick'
        }
    ],
    initComponent: function(){
         Ext.apply(this, {
            layout: 'fit',

       items: [
        {
            xtype:'textareafield',
            name: 'name',
            autoScroll: true

        }]
         });
    this.callParent();
    }

点击下一个或上一个图标,我想隐藏我在控制器中处理的上一个和下一个图标。 要显示Icon,我使用的是Ext.getCmp(图标的id).show(); 它工作正常但如果两个选项卡调用相同的视图它给出重复ID错误。

我想根据tbar中指定的名称字段显示()/ hide()。 我该怎么办?

1 个答案:

答案 0 :(得分:0)

我建议使用ComponentQuery来迭代任何ExtJS组件的元素,如果你不想对id进行硬编码。对于Ex: -

var tabBar = Ext.ComponentQuery.query('tab');

然后你可以进一步遍历tabBar元素的元素来对它们进行操作。

tabBar.forEach(function(i){ 
    //Here you can further iterate through another level if any,and operate on the elements
    i.setHidden(true);
});

有关详细信息,请参阅: - Sencha Docs For Component Query