Rick Hoving
Rick Hoving

Reputation: 3575

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?

Upvotes: 1

Views: 7061

Answers (1)

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12959

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

Upvotes: 3

Related Questions