How to write conditional in List template?

Hi!!

I have a question: How to write conditional in List template?? information for each listitem not be the same. Depending on the data received will show one or the other elements. So I need to include a canditional to check every item in the list, is this possible??

I see that in Sencha is very easy, but I cant find a solution in your framework

Here it is an example: sencha.com/forum/showthread. … e&langid=4

thanks for reading and have a nice day

You can define template as function

{ view:"list", template:function(obj){ if (obj.some) return obj.propA; else return obj.propB; } }

This code is nice, but it isn’t useful for that I want to do

here is the problem:

{ view: 'list', id: 'lista', type : { css : "frame", height : "auto", width : "auto" }, scroll: true, datatype: 'json', select : true, template : '<table>' +'<tbody>' +'<tr><td><b>#name#</b></td></tr>' +'<tr><td style="font-size:80%;">#address#</td></tr>' +'</tbody>' +'</table>' +'<table>' +'<tbody>' +'<tr>' +'<tpl if=#turismo#>' +'<td style="width:40px"><img src="images/turismo.gif"></td>' +'</tpl>' +'<tpl if=#cuatroxcuatro#>' +'<td style="width:40px"><img src="images/4x4.gif"></td>' +'</tpl>' +'<tpl if=#suv#>' +'<td style="width:40px"><img src="images/suv.gif"></td>' +'</tpl>' +'<tpl if=#furgo#>' +'<td style="width:40px"><img src="images/lighttruck.gif"></td>' +'</tpl>' +'</tr>' +'</tbody>' +'</table>' , url: 'resources/data/talleres.json', },

and here it is the JSON where I am taking the data:

[code][
{
“id”: 0,
“name”: “XXXXXXXX”,
“lat”: “42.77”,
“lon”: “-7.68”,
“address”: “XXXXXX”,
“turismo”: true,
“cuatroxcuatro”: true,
“suv”: true,
“furgo”: true

    },
 
    {
        "id": 1,
        "name": "XXXXXXX",
        "lat": "40.34",
        "lon": "-3.83",
        "address": "XXXXXXXX",
        "turismo": true,
        "cuatroxcuatro": true,
        "suv": true,
        "furgo": true,
        "tfno": "666666666"
    }

][/code]

So the problem is that I want to show images depending if the fields are defined, (cuatroxcuatro, suv, furgo & turismo), so I need some like the line in the template.

Ask for more info if it’s needed

Thanks so much

Why not to use native js if construction ?

[code]{ view: ‘list’,
id: ‘lista’,
type : {
css : “frame”,
height : “auto”,
width : “auto”
},
scroll: true,
datatype: ‘json’,
select : true,
template : function(obj){
var html = ’


+’’
+’’
+’’
+’’
+’
’+obj.name+’
’+obj.address+’#

+’’
+’’
+’’;
if (obj.turismo)
html += ‘’
if (obj.turismo)
html += ‘’
if (obj.suv)
html += ‘’
if (obj.furgo)
+’’;
html += ‘
     return html;
     },
     url: 'resources/data/talleres.json',
  },[/code]

It works like a charm!!! thanks so much!