我想在JavaScript中使用JSTL庫。我可以使用JSTL在JavaScript中使用foreach標籤選擇標籤嗎?
我的代碼如下。
<script type="text/javascript">
var grid_data =
[
<c:forEach items="${LIST}" var="list" varStatus="status">
<c:if test="${ status.index == 0 }">
{id:'${list.NOTICE_ID}'}
</c:if>
</c:forEach>
];
</script>
此代碼運行良好,但它不適用於選擇標籤。
有什麼特別的原因嗎?有誰能夠幫助我?
// Syntax error on tokens ** especially in script not in html body **
<script type="text/javascript">
var grid_data =
[
<c:forEach items="${LIST}" var="list" varStatus="status">
<c:choose>
<c:when test="${ status.index == 0 }">
{id:'${list.NOTICE_ID}'}
</c:when>
<c:otherwise>
, {id:'${list.NOTICE_ID}'}
</c:otherwise>
</c:choose>
</c:forEach>
]
</script>
定義 「它不工作」。怎麼了? ''在哪裏?在這兩種情況下產生了什麼? –
抱歉有編輯錯誤。我添加了標記。 「它不工作」意味着有錯誤。 - 「令牌語法錯誤,刪除這些令牌。」 – user2940817