0

仅当数据数组在某个节点上有项目时,如何才能显示 XTemplate?

例如下面,我只想显示“项目”的模板。(显示第 28 天的“项目”,第 27 天不显示任何内容)

目前它为数组中的所有项目创建 ap 标签,这是我不想要的......

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

来自服务器的数据:

{
  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
     }
  ]
 }

非常感谢

4

2 回答 2

0

Ext.XTemplate查看文档中的“使用基本比较运算符进行条件处理”部分。http://docs-devel.sencha.com/extjs/4.2.1/#!/api/Ext.XTemplate

在我的脑海中,您可以执行以下操作:

<tpl if="items.length">
   <tpl for="items">
      ...
   </tpl>
</tpl> 
于 2013-06-02T01:12:34.240 回答
0

我不确定你是否正确,但它认为是:

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

希望能帮助到你

于 2013-06-02T01:13:32.067 回答