본문 바로가기
JAVA/JSTL

<c:> 형식으로 배열출력하는 기본 코드

by java나유 2023. 11. 17.
var testArray = new Array();
 for(var i=0; i<${sample}.length; i++){
	testArray[i]=sample[i].sampleId;
	}

 

바닐라 자바스크립트에서는 이렇게 쓰면 출력이 되지만, 문제는 ${함수} 형태로 배열을 출력 할 수 없다.

 

자바스크립트 안에서 <c:>를 사용할 수 있기때문에

그럴 때는 이렇게 사용하면 된다.

 

<c:forEach items="${sample}" var="item" varStatus="status">
	var test = parseInt('${status.index}');
	testArray['${status.index}'] = parseInt("${item.countOfConectId}");	
	monthArray['${status.index}'] = "${item.yearMonth}";	
</c:forEach>
728x90

'JAVA > JSTL' 카테고리의 다른 글

fmt태그 <fmt:formatNumber>  (0) 2024.01.25

댓글