Search code examples
sencha-touch-2carouselsencha-architect

How can I set a value for Ext.Img ->"src" dynamically in Sencha Architect


I am using Image view to display image. Can some tel me how set the url value dynamically,so that I can display images for server. Below is the code which I am trying.

Ext.define('MyApp.view.MyImage', {
    extend: 'Ext.Img',
    alias: 'widget.myimage',

    config: {
        height: 201,
        id: 'galimage',
        width: 201,
        src: 'http://localhost/galerie/albums/'+filepath+filename
    }

}); 

filepath and filename are variables which I want to set with src > these are coming from controller.

Please help me to find the solution. Thanks.


Solution

  • try this,

    Ext.define('MyApp.view.MyImage', {
    extend: 'Ext.Img',
    alias: 'widget.myimage',
    
    config: {
        height: 201,
        id: 'galimage',
        width: 201,
        src: 'http://localhost/galerie/albums/'+filepath+filename
    }
    }); 
    

    then you can use like this to set your image dynamically whenever you want,

    Ext.getCmp('galimage').setSrc("resources/Images/Img_Food_New.png"); // in setSrc you can give path of your image
    
                            OR
    
    Ext.getCmp('galimage').setHtml('<img src="resources/Images/Img_Food_New.png" height="100%" width="100%"/>'); // in src you can give path of your image
    

    hope this may help you.