View Full Version : Dynamically load IMG without using ID

24 Sep 2014, 3:44 AM
Hello to everybody.

I'd like to load dinamically a image. Right now i am able to do in the following way

Ext.get('myimg').dom.src = 'mypath';

Btw this solution (even if it works!) seems to me not elegant at all. I have to define an ID unique for such IMG.
As suggested by Sencha developer, we should avoid to use id in the code because we may sometimes add components with same id.
Suppose i'm in a form 'myform' and i would like to perform an action, to change the src-path of one of the image inside such form.

I would like to do it without assigning an id to my img, but, hopefully, calling my form, find the element inside who's name is 'myimg' and then set the src.

How can i do that?

Hope that i was enough clear.
thanks in advance.

---- edit ----
I can access to the img by using the first line.

var img = Ext.ComponentQuery.query('#myimg');

but then img.src give me undefined.
any idea which is the right field to set?

25 Sep 2014, 10:48 PM

One you have a reference to your image component you can use its setSrc setter method.