Search code examples
if-statementsencha-touch-2itemtemplate

short if statement in itemTpl configuration Sencha Touch 2


I was wondering, is it possible to state an if statement (short or not) inside the itemTpl configuration of a List in Sencha Touch.

//My Model
Ext.define('ListItem', {
            extend: 'Ext.data.Model',
            config: {
                fields: ['number', 'someBoolean']
            }
        });
//The List
var MyList = Ext.create("Ext.List", {
        itemTpl : "{number} <br />"+
                    //THIS LINE BELOW IS WHAT ITS ALL ABOUT
                ("{someBoolean}")? + "The boolean was true" : +"It was false" ,
        store: oListStore,
    });

This results in a List filled with items representing NaN on the screen.

Is there a way to program around this?


Solution

  • Take a look at Ext.XTemplate

    Here's an example

    itemTpl: new Ext.XTemplate(
        '<p>Name: {name}</p>',
        '<p>Kids: ',
        '<tpl for="kids">',
            '<tpl if="age &gt; 1">',
                '<p>{name}</p>',
                '<p>Dad: {parent.name}</p>',
            '</tpl>',
        '</tpl></p>'
    ),
    

    Hope this helps