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>
now what you have is something like this in javascript
var countries = [
{country:"USA",
provinces: [
"Ohio",
"New York",
"California"
]},
{country:"Canada",
provinces: [
"Ontario",
"Northern Territory",
"Sascetchewan"
]},
]
The other option would be to make your output look like the javascript I posted.
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>
];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…