View Full Version : problem with display default image in list

manish khamar
26 Aug 2011, 1:06 AM

I have one complex problem.

I parse json using ajax request and get response properly.
then show it in list as below:

method: 'post',
success: function(response){
recdata = Ext.decode(response.responseText);
Ext.regModel('User', { fields: ['address']
var c = new Ext.data.Store({
model: 'User',
autoLoad: true,
data: [recdata],
var myTpl = new Ext.XTemplate(
'<tpl for="."><div class="user"><div>{address}</div><div class="pic"><img src="{[values.picture[0].url]}" ></div></div></tpl>'

var list = new Ext.List({ fullscreen: true,
itemTpl :myTpl,
store : c
I can list all data properly from json means address and image both.

But now problem is that in my json some url tag do not consist any image string so i can not display that image.So I want to display some defualt image there.But i have no idea how i can do that.
so pls help me to solv it.:(

26 Aug 2011, 6:57 AM
Within your XTemplate, you could use:

<tpl if="address!=''">
<img src="default_image_url.jpg">

refer: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.XTemplate for more info

manish khamar
26 Aug 2011, 9:34 PM
I see your reply but I can not get proper idea.

var myTpl = new Ext.XTemplate(

'<tpl for="."><div class="pic" style="width:35%;float:left;padding:0.2em 0 0 0;"><img src="{[values.picture[0].url]}" width="90" height="75" ></div></tpl>'

In above template I get images using '{[values.picture[0].url]}'

But sometime in json picture tag has no url tag .hence it show me error.

So how i can solve it using default image
I show some part of json as below:

In above json u can see that in picture tag has no url in srno:2.
So i want to display there default image.
Pls help me.

28 Aug 2011, 4:49 AM
well, you probably have to create an if clause that checks against 'picture' then. If picture is an empty string (aka falsy) then show the default image.

Another option is to add the default image in AbstractView#prepareData.

Not sure how this works in Sencha Touch though (since you refer to 'Ext.List')