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

Extjs 如何通过组件对象的名称获取组件对象?,extjs,Extjs,我使用的formPanel如下所示: tbar: [ { iconCls:'icon-previous', hidden: true, //id:'previous', name:'previous', handler:'onPClick' }, { xtype: 'tbfill' },

我使用的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();
    }
单击下一个或上一个图标时,我想隐藏我正在控制器中处理的上一个和下一个图标。 要显示图标,我使用Ext.getCmp(图标的id).show(); 它工作正常,但如果两个选项卡调用同一个视图,则会出现重复id错误

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

如果您不想硬编码id,我建议使用
ComponentQuery
迭代任何
ExtJS
组件的元素。例如:-

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);
});
有关更多信息,请参阅:-

可能重复的