在煎茶触摸列表中动态设置项目Tpl中的图像



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

这是我的商店:

Ext.define('MyApp.model.Sample', {
           extend: 'Ext.data.Model',
           config: {
           fields: [ 
                    { name: 'uName', mapping: '@name' },
                    { name: 'uId', mapping: '@id' }
                    ]
                }
           });

在我的列表项Tpl中,我能够显示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'
                }
              }
    ),
你不需要

使用函数。 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>'
);

希望这有帮助

最新更新