SENCHA TOUCH / EXTJS SHOW XTEMPLATE ONLY IF ARRAY NODE CONTAINS ITEMS

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 2644  View(s)
Ratings:
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.  
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Sencha Touch / ExtJs show XTemplate only if array node contains items

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!