如果数据数组在某个节点上有项,我如何才能显示一个XTemplate ?
例如下面,我只想显示我的"items"模板。(显示第28天的"项目",而不显示第27天的项目)
目前它为数组中的所有项目创建了一个p标签,这是我不想要的…
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
}
]
}
谢谢
我不确定是否理解对了,但它认为是:
itemTpl: [
'<tpl for="items">',
'<tpl if="values.classname">',
'<p>{classname} {typename}</p>',
'</tpl>',
'</tpl>',
].join('')
希望有所帮助
查看Ext.XTemplate
文档中的"使用基本比较运算符的条件处理"一节。http://docs-devel.sencha.com/extjs/4.2.1/# !/api/Ext.XTemplate
我马上想到,你可以这样做:
<tpl if="items.length">
<tpl for="items">
...
</tpl>
</tpl>