如果数据数组在某个节点上有项目,我该如何显示XTemplate?
例如下面,我只想显示“项目”的模板。 (显示第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
}
]
}
非常感谢
答案 0 :(得分:0)
查看Ext.XTemplate
文档中的“使用基本比较运算符进行条件处理”部分。 http://docs-devel.sencha.com/extjs/4.2.1/#!/api/Ext.XTemplate
在我的头顶,你可以做类似的事情:
<tpl if="items.length">
<tpl for="items">
...
</tpl>
</tpl>
答案 1 :(得分:0)
我不确定你是否正确,但它认为是:
itemTpl: [
'<tpl for="items">',
'<tpl if="values.classname">',
'<p>{classname} {typename}</p>',
'</tpl>',
'</tpl>',
].join('')
希望有所帮助