2

我正在使用图像视图来显示图像。可以告诉我如何动态设置 url 值,以便我可以显示服务器的图像。下面是我正在尝试的代码。

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
    }

}); 

文件路径和文件名是我想用 src 设置的变量 > 这些来自控制器。

请帮助我找到解决方案。谢谢。

4

2 回答 2

8

试试这个,

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
}
}); 

然后您可以像这样使用它来随时动态设置图像,

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

希望这可以帮助你。

于 2013-04-01T04:24:36.643 回答
3

在图像组件上使用 setSrc()

http://docs.sencha.com/touch/2-2/#!/api/Ext.Img-method-setSrc

于 2013-04-01T01:38:55.280 回答