Learner
Learner

Reputation: 281

Get ExtJS component by class

I want to retrieve ExtJS component by using class name that is I want the same result when I tried to retrieve element by using id. I can do it by using id but there are some issues occurs when I provide id to my components. Below is one item which present on one page and I want to get it on another page (internally pages are connected) by using class name.

  {
    ref: 'reasonCodeField',
    cls: 'reason-code-field',
    xtype: 'enumcombo',
    enumName: 'SCH.TrackingEventReasonCodes',
    allowBlank: false
  }

Now how can I get component by using class name?

Upvotes: 1

Views: 716

Answers (1)

srk
srk

Reputation: 1901

You can try to call Ext.getCmp with the ID from the DOM element:

const element = document.querySelector('.reason-code-field');
const component = Ext.getCmp(element.id);

Two big caveats:

  1. I'm not sure if this will always work. It works for me in a simple example.
  2. There is probably a better way to do whatever it is you are trying to accomplish (see my comment asking for more details).

Upvotes: 1

Related Questions