繁体   English   中英

Sencha touch - Ext.XTemplate if / else not working

[英]Sencha touch - Ext.XTemplate if/else not working

嗨,我是Sencha touch的新手。 我在使用itemTplExt.dataview.List显示数据时itemTpl 这是我如何在config设置itemTpl

itemTpl: new Ext.XTemplate(

            '<div class="featureImageHolder"><img class="featureImage" src="{itemImage}" alt="{itemName}" /></div>',

            '<span class="item">',
                '<h3 class="saleName">{itemName}</h3>',
                '<span class="priceOptions">',
                '<tpl for="prices">',
                    '<span class="priceOptionReg">',
                        '<tpl if="priceOptionDesc">{priceOptionDesc}</tpl> ',
                        '<tpl if="priceOptionReg">{priceOptionReg}</tpl>  ',
                        '<tpl if="priceReg">${priceReg}</tpl>  ',
                        '<tpl if="priceRegSuffix">{priceRegSuffix}</tpl> ',
                    '</span>',
                    '<tpl if="priceSale"><span class="priceOptionSale">',
                        '<tpl if="priceSaleDesc">{priceSaleDesc}</tpl> ',
                        '<tpl if="priceOptionSale">{priceOptionSale}</tpl>  ',
                        '<tpl if="priceSale">${priceSale}</tpl>',
                        '<tpl if="priceSaleSuffix">{priceSaleSuffix}</tpl> ',
                    '</span></tpl>',
                '</tpl>',
                '</span>',
            '</span>',
            '<div class="clear"></div>'
        ),

它完美地工作并显示产品列表。 但是现在我需要更改第一个记录的CSS类,因为它是一个广告横幅。 所以我使用以下if语句:

itemTpl: new Ext.XTemplate(
                '<tpl if={isBanner} === true>',
                    '<div class="myTestClass">{itemImage}</div>',

                '<tpl elseif={isBanner} === false>',
                    '<div class="featureImageHolder"><img class="featureImage" src="{itemImage}" alt="{itemName}" /></div>',
                '</tpl>',


                '<span class="item">',
                    '<h3 class="saleName">{itemName}</h3>',
                    '<span class="priceOptions">',
                    '<tpl for="prices">',
                        '<span class="priceOptionReg">',
                            '<tpl if="priceOptionDesc">{priceOptionDesc}</tpl> ',
                            '<tpl if="priceOptionReg">{priceOptionReg}</tpl>  ',
                            '<tpl if="priceReg">${priceReg}</tpl>  ',
                            '<tpl if="priceRegSuffix">{priceRegSuffix}</tpl> ',
                        '</span>',
                        '<tpl if="priceSale"><span class="priceOptionSale">',
                            '<tpl if="priceSaleDesc">{priceSaleDesc}</tpl> ',
                            '<tpl if="priceOptionSale">{priceOptionSale}</tpl>  ',
                            '<tpl if="priceSale">${priceSale}</tpl>',
                            '<tpl if="priceSaleSuffix">{priceSaleSuffix}</tpl> ',
                        '</span></tpl>',
                    '</tpl>',
                    '</span>',
                '</span>',
                '<div class="clear"></div>'
            ),

问题是if/elseif是否都为每条记录执行。 如果我使用if/else它会在控制台中出错。

Uncaught SyntaxError: Unexpected token else 

你可以看到我用过

'<tpl if={isBanner} === true>',

我也用过

'<tpl if={isBanner} == true>',

我也尝试了许多变量,例如比较数值而不是布尔值,并使用&gt; 或者&lt; 还尝试比较字符串值。 但是对于所有变体, if/elseif都在执行, if/else给出错误。

任何帮助表示赞赏,我只需更改第一个记录的课程。

如果isBanner是布尔值,这将起作用

'<tpl if="isBanner">',
     '<div class="myTestClass">{itemImage}</div>',
'<tpl else>',
     '<div class="featureImageHolder"><img class="featureImage" src="{itemImage}" alt="{itemName}" /></div>',
'</tpl>',

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM