Home > DeveloperSection > Forums > Sencha Touch / ExtJs show XTemplate only if array node contains items
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    June-03-2013 2:24 AM

 Sencha Touch Sencha Touch 
Ratings:


 1 Reply(s)
 2081  View(s)
Rate this:
Hi Developers,

How can I show a an XTemplate only if the data array has items at a certain node?

For example below, I only want to show my template for "items." (show day 28's "items" and show nothing for day 27)

Currently it creates a <p> tag for all items in the array, which what I don't want...

        itemTpl     :    new Ext.XTemplate(
                '<tpl for="items">'+
                  '<p>{classname} {typename}</p>'+
                '</tpl>'
        ),

Data from the server:

{
  day:27,
  iscurrentmonth:false,
  issunday:false,
  date:"2013-05-27",
  schedulesection:{
     id:46694897,
     markingperiodid:15156,
     name:"Sunday",
     number:0
  },
  announcements:[

  ],
  items:[

  ]
},
 {
  day:28,
  iscurrentmonth:false,
  issunday:false,
  date:"2013-05-28",
  schedulesection:{
     id:46695811,
     markingperiodid:15156,
     name:"Monday",
     number:1
  },
  announcements:[

  ],
  items:[
     {
        id:134513,
        title:"Subject",
        typeid:3,
        typename:"Essay",
        author:"Bryan Fisher",
        classname:"English 9A",
        classid:344499,
        courseid:60555
     },
     {
        id:134485,
        title:"Subject",
        typeid:3,
        typename:"Essay",
        author:"Bryan Fisher",
        classname:"English 10",
        classid:344500,
        courseid:60555
     }
  ]
 }

Much thanks for your positive response.  


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-03-2013 9:02 AM

Hi Ankita,

Try as following,

itemTpl: [
    '<tpl for="items">',
        '<tpl if="values.classname">',
            '<p>{classname} {typename}</p>',
        '</tpl>',
    '</tpl>',
].join('')

Hope it helpful for you.

Don't want to miss updates? Please click the below button!

Follow MindStick