2015-01-13 33 views
0

如何僅在${link[i].alt}不爲空時添加邏輯才能進行循環?
如何添加索引到jsp var ...像${link${i}.credit} ??如何將循環索引添加到JSP變量

<c:forEach var="i" begin="1" end="6"> 
    <li>${i} 
     <a class="lnid-sec1_lnk${i}" href="${link.href}"> 
      <div class="l-wrapper"> 
       <img data-src="${link1.credit}" src="${link1.credit}" alt="${link1.alt}" width="100"> 
       <div class="team-name"> 
        <span>${link1.alt}</span> 
       </div> 
      </div> 
     </a> 
    </li> 
</c:forEach> 

回答

1

答案:1個

<c:if test="${!empty link[i].alt}"></c:if> 

答案:2個

<c:set var="your_var" value="${link[i.index].credit}"/> 
+0

$ {link1.credit} - Link 1 credit $ {i} ** - index $ {link [i.index] .credit} - Link credits從循環 - 沒有返回值//我得到的數據是social-.jpg--鏈接1信用1 ** - 索引 - 來自循環的鏈接信用 – tv3free

+0

$ {link [item.index] .alt} - 不工作 – tv3free

1

添加varStatus

所以

<c:forEach var="i" begin="1" end="6" varStatus="yourIndex"> 

然後

($ {} yourIndex.index)包含索引

+0

謝謝回答。但 $ {link [item.index] .alt} - 不工作 – tv3free

0

對於沒有空,你可以使用這個

<c:if test="${!empty link[i].alt}"></c:if> 
相關問題