0

我必须在列表的一行中设置带有文本的图像。但是要在运行时选择图像。

这是我的商店:

Ext.define('MyApp.model.Sample', {
           extend: 'Ext.data.Model',

           config: {
           fields: [ 
                    { name: 'uName', mapping: '@name' },
                    { name: 'uId', mapping: '@id' }
                    ]
                }
           });

在我的列表 itemTpl 中,我能够显示uName,并且我创建了一个假设返回所需图像的函数(getImageURL),那么我应该如何使用或者使用 上述uId的方式/语法是什么(其中值为 0 或 1)

这是我的清单:

  itemTpl : new Ext.XTemplate("<img src=\"{[this.getImageURL()]}\" width=\"20\" height=\"20\"></img><span>    {uName}</span>",
              {
               getImageURL : function()
                {

                // I have to return either of two images
                // if  uId = 0, return 'resources/images/Image0.png'
                // if uId = 1, return 'resources/images/Image1.png'

                }
              }
    ),
4

1 回答 1

2

您不需要使用函数。XTemplate提供ifelse声明。

看看这里

例子

var tpl = new Ext.XTemplate(
    '<p>Name: {name}</p>',
    '<p>Kids: ',
    '<tpl for="kids">',
        '<p>{name} is a ',
        '<tpl if="age &gt;= 13">',
            '<p>teenager</p>',
        '<tpl elseif="age &gt;= 2">',
            '<p>kid</p>',
        '<tpl else>',
            '<p>baby</p>',
        '</tpl>',
    '</tpl></p>'
);

希望这可以帮助

于 2012-07-03T12:22:43.757 回答