PDA

View Full Version : How to get Object from its ID



aresot
19 Sep 2007, 11:37 PM
I have bunch of Buttons, DatePickers and other ExtJS objects created during init. Is there way to get that object from its ID? I tried Ext.get(id) but it returns Element and Ext.getDom(id) is DOM object. How do I get say existing Button object from its ID?

Thanks in advance.

evant
19 Sep 2007, 11:45 PM
Ext.ComponentMgr.get(id);


This works in most cases, however the fact that you need to do this suggests you might have a design issue with your application.

aresot
19 Sep 2007, 11:52 PM
Thanks for the reply. Can you please explain design issue comment? Say I have complex UI form where clicking on one button or switching focus will trigger other form controls update its value, be disabled or hidden. If Im not using IDs thats a lot of global variables (which I don't like in general) to store if I need to process events of clicking on say Button and update DatePicker value.
From old desktop App days it was general practice to get all basic elements by their IDs wether its Win app or Java.

Thanks again.

evant
19 Sep 2007, 11:55 PM
Generally, I like to keep a reference to the object when I create it somewhere. You can generally group your objects into some kind of logical structure, for example:



UISection1 = function()
{
var but1, but2;
return {
init: function()
{
but1 = new Ext.Button(...);
but2 = new Ext.Button(...);
},

getButton1: function()
{
return but1;
}
};
}();

aresot
20 Sep 2007, 3:29 PM
Thanks evant. That makes sence. One case where I argue against it is if those objects have to talk to each other, meaning those variables are outside the scope of object.

Cheerz.