Results 1 to 2 of 2

Thread: Dynamically load IMG without using ID

  1. #1
    Ext JS Premium Member
    Join Date
    Feb 2012
    Posts
    44
    Answers
    3

    Default Dynamically load IMG without using ID

    Hello to everybody.

    I'd like to load dinamically a image. Right now i am able to do in the following way
    Code:
    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.
    Code:
    var img = Ext.ComponentQuery.query('#myimg');
    console.log(img);
    console.log(img.src);
    but then img.src give me undefined.
    any idea which is the right field to set?
    Last edited by [email protected]; 24 Sep 2014 at 5:01 AM. Reason: additional infor

  2. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    Hi,

    One you have a reference to your image component you can use its setSrc setter method.
    http://docs.sencha.com/extjs/4.2.3/#...-method-setSrc

    Code:
    Ext.ComponentQuery.query('#myimg')[0].setSrc('new/image/source/file.jpg');

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •