Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs select component by id starting with a string

Tags:

extjs

i need to create a component dynamically by a button click. My restrictions are:

  1. It's going to has an Id starts with a fixed string like 'myComp_' and followed by a random number
  2. At any time there will be only one component that has an id starts with 'myComp_xxx'

So before creating the component i have to check if there's any created before and remove it... My problem starts here. Ext.getCmp() wants the specific id. But i only have that fixed string : myComp_...

Is there any way to get the component created before???

Thanks in advance and sorry about my English.

like image 771
DonkeyKong Avatar asked Oct 12 '12 13:10

DonkeyKong


2 Answers

For ExtJs 4.X use Ext.ComponentQuery.query('*[id^=myComp_xxx]');

For ExtJs 3.X you can either use the following

var el = Ext.query('*[id^=myComp_xxx]');
var cmp = Ext.getCmp(el.id);

Or (this one i haven't tried personally, but i think it should work) if the component is a child of a component that you can access, then:

var el = parentComp.find("action","btn");

and set a property called action : btn in the button config.

like image 168
Varun Achar Avatar answered Oct 18 '22 19:10

Varun Achar


I think what you are looking for is DomQuery.

Ex:

Ext.query("*[id^=myComp_xxx]")
like image 34
Arun P Johny Avatar answered Oct 18 '22 18:10

Arun P Johny