使用JSTL正确创建javascript数组for:each
我试图基于来自servlet的数据创建一个数组对象,因为尝试使用Javascript变量c:if无效。会话变量“preeditList”是由3个字段组成的数组。以下是我的JSP中的以下数组:使用JSTL正确创建javascript数组for:each,javascript,arrays,jstl,Javascript,Arrays,Jstl,我试图基于来自servlet的数据创建一个数组对象,因为尝试使用Javascript变量c:if无效。会话变量“preeditList”是由3个字段组成的数组。以下是我的JSP中的以下数组: var checkedArray = [ <c:forEach items="${preeditList}" var="preeditList" varStatus="status"> {"schedulekey": '${preedi
var checkedArray =
[
<c:forEach items="${preeditList}" var="preeditList" varStatus="status">
{"schedulekey": '${preeditList.getCHK_SCHEDULE_NUMBER()}',
"contractkey": '${preeditList.getCHK_CONTRACT_YEAR()}',
"prevStatus": '${preeditList.getCHK_STATUS()}'
}
<c:if test="${!status.last}">
,
</c:if>
</c:forEach>
] ;
如果这是好的,那么我在语法上犯了什么错误来实现这一点
再次感谢
var countries = [
<c:forEach items="${countryList}" var="country" varStatus="status">
{country: '${country.name}',
provinces : [
<c:forEach items="${country.provinces}" var="province" varStatus="provinceStatus">
'${province.name}'
<c:if test="${!provinceStatus.last}">
,
</c:if>
</c:forEach>
]}
<c:if test="${!status.last}">
,
</c:if>
</c:forEach>
];
我从问题中找到了解决办法 非常感谢这太棒了:)
var countries = [
<c:forEach items="${countryList}" var="country" varStatus="status">
{country: '${country.name}',
provinces : [
<c:forEach items="${country.provinces}" var="province" varStatus="provinceStatus">
'${province.name}'
<c:if test="${!provinceStatus.last}">
,
</c:if>
</c:forEach>
]}
<c:if test="${!status.last}">
,
</c:if>
</c:forEach>
];
var countries = new Array();
<c:forEach items="${countryList}" var="country" varStatus="status">
countryDetails = new Object();
countryDetails.country = ${country.name};
var provinces = new Array();
<c:forEach items="${country.provinces}" var="province" varStatus="provinceStatus">
provinces.push(${province.name});
</c:forEach>
countryDetails.provinces = provinces;
countries.push(countryDetails);
</c:forEach>
var countries = [
{country:"USA",
provinces: [
"Ohio",
"New York",
"California"
]},
{country:"Canada",
provinces: [
"Ontario",
"Northern Territory",
"Sascetchewan"
]},
]