2014-09-29 80 views
0

我有一個嵌套的jstl forEach循環,並且由於某種原因,每當代碼進入最內層循環時,索引重新啓動。因此,當我嘗試使用索引作爲ID的一部分時,按鈕會生成重複ID。不應該繼續索引或我不正確地看這個?這是一段代碼片段。JSTL for each indexing issue

<c:forEach items="${groups}" var="group" varStatus="groupstatus"> 

     <c:forEach items="${items}" var="item" varStatus="itemstatus"> 

      <c:forEach items="${form.properties}" var="property" varStatus="status"> 

        <button id="btn-${status-index}">title here</button> 

      </c:forEach> 

     </c:forEach> 

    </c:forEach> 
+0

向我們顯示用於顯示按鈕/ ID的代碼。您目前使用哪個索引? 'groupstatus'? 'itemstatus'? 'status'? – 2014-09-29 16:23:14

+0

在這一點上,我將使用狀態來構建ID的我更新上面的代碼來顯示按鈕。 – vslat 2014-09-29 16:48:10

+0

這是否意味着'$ {status.index}'(注意''.')? – 2014-09-29 16:53:27

回答

0

status將在內部循環局部。它將重置爲每個迭代${items}

如果您正在尋找該級別的全球唯一ID,可能需要類似btn-${groupstatus.index}-${itemstatus.index}-${status.index}的東西。