日期:2014-05-18  浏览次数:20783 次

list在ww:iterator标签里取不到size,在外面就可以取到
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="/struts-tags" prefix="ww" %>
<%@ taglib uri="/struts-tags" prefix="ui" %>
{results:"<ww:property value="teachSubjectList.size"/>",rows:[
<ww:iterator value="teachSubjectList" status="liststatus" id="list">
{subjectName:"<ww:property value="subjectName"/>",
teachSubject:"<ww:property value="teachSubject"/>"
<ww:if test="#liststatus.count==teachSubjectList.size">}</ww:if>
<ww:else>},</ww:else>
</ww:iterator>
]
}


上面是我的数据页
{results:"5",rows:[ {subjectName:"数学", teachSubject:"SHUXUE" }, {subjectName:"语文", teachSubject:"YUWEN" }, {subjectName:"英语", teachSubject:"YINGYU" }, {subjectName:"物理", teachSubject:"WULI" }, {subjectName:"化学", teachSubject:"HUAXUE" }, ] }

这是我打印出来的josn数据
在迭代标签前,results的是取size的值,是5,在里面,size的值取不出来,判断出了问题,多了一个逗号,有人知道这是什么原因么?
在来一个size在外面能取到的
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="/struts-tags" prefix="ww" %>
<%@ taglib uri="/struts-tags" prefix="ui" %>
{results:"<ww:property value="teachSubjectList.size"/>",rows:[
<ww:iterator value="teachSubjectList" status="liststatus" id="list">
{subjectName:"<ww:property value="subjectName"/>",
teachSubject:"<ww:property value="teachSubject"/>",
liststatus:<ww:property value="#liststatus.count" />,
listSize:<ww:property value="teachSubjectList.size" default="null"/>
<ww:if test="#liststatus.count==teachSubjectList.size">}</ww:if>
<ww:else>},</ww:else>
</ww:iterator>
]
results:"<ww:property value="teachSubjectList.size"/>"
}


这是数据页,下面是打印的josn结果
{results:"5",rows:[ {subjectName:"数学", teachSubject:"SHUXUE", liststatus:1, listSize:null }, {subjectName:"语文", teachSubject:"YUWEN", liststatus:2, listSize:null }, {subjectName:"英语", teachSubject:"YINGYU", liststatus:3, listSize:null }, {subjectName:"物理", teachSubject:"WULI", liststatus:4, listSize:null }, {subjectName:"化学", teachSubject:"HUAXUE", liststatus:5, listSize:null }, ] results:"5" }
jsp java list iterator josn