2013-07-23 105 views
0

我正試圖對當前提交的內容進行比較。我有以下代碼:邏輯:迭代比較下一個值

<logic:iterate id="anItem" name="dataPage" property="filingsList" 
    indexId="myInd"> 
    <bean:define id="currentSubmissionId" type="java.lang.String" 
    name="anItem" property="denseRank"/> 

我想這樣做:

<logic:equal name="dataPage" property="currentSubmissionId" 
value="nextSubmissionId???"> 

    <img id="plus<%=rowCount%>" class="cursor" 
     src="<icis2:icisRes/>images/plus.gif" 
     onclick="toggle('<%=rowCount%>', this, 
     jQuery('#minus<%=rowCount%>'))"/> 

    <img id="minus<%=rowCount%>" class="cursor" 
     src="<icis2:icisRes/>images/minus.gif" onclick="toggle('<%=rowCount%>', 
     this, jQuery('#plus<%=rowCount%>'))" style="display: none;"/> 
</logic:equal> 

感謝,

湯姆

+0

我還沒有使用struts,但可以幫助你的邏輯。比較後你做了什麼?存儲更大的數字還是更小的? – JNL

+0

我想比較當前的提交到下一個,如果他們是相同的打印那兩條線。 –

+0

那你怎麼存儲它?作爲字符串? – JNL

回答

0
1. Create a temp string variable to "", 
2. Store the current String here 
3. Iterate, and compare. 
4. As you iterate check if equal or not. 
5. If equal print else copy next string to the variable. 

這裏是代碼。

String[] someArrayOfStrings; // Store the Strings here. You can use ArrayList too. 
    String tempString = "";  // Recommend to use ArrayList. 

    for(int count=0; count<someArrayOfStrings.length-1; count++){ 
     tempString = someArrayOfStrings[count]; 

     if(tempString.equalsIgnoreCase(someArrayOfStrings[count+1])){ 
      System.out.print(tempString);  
     } 
    } 

讓我知道它是否有幫助。

+1

感謝您的幫助! –