就是下面这段代码,主要的。通过add按钮可以弹出一个小窗口选择一条数据,添加。
但是我现在不想让s:iterator中有重复数据,不让postName重复。
<s:if test="functionGroupBO.postAccountVOs != null">
<script>existRow = 0;</script>
<s:iterator value="functionGroupBO.postAccountVOs" status="stat">
<tr class="dataRow">
<td>
<input type="checkbox" name="delDetail" value="tr0" />
<input type="hidden" name="postIds"
value='<s:property value="postId"/>' />
</td>
<td>
<input type="text" name="postNames" readonly="readonly"
value='<s:property value="postName"/>' />
</td>
<td>
<input type="text" name="userNames" readonly="readonly"
value='<s:property value="userAccountVO.userName"/>' />
</td>
</tr>
<script>existRow++;</script>
</s:iterator>
</s:if>
<s:else>
<tr class="dataRow">
<td>
<input type="checkbox" name="delDetail" value="tr0" />
<input type="hidden" name="postIds"
value='<s:property value="postId"/>' />
</td>
<td>
<input type="text" name="postNames" readonly="readonly"
value='<s:property value="postName"/>' />
</td>
<td>
<input type="text" name="userNames" readonly="readonly"
value='<s:property value="userAccountVO.userName"/>' />
</td>
</tr>
</s:else> </table>
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="button" name="button3" id="addRowBtn" value="Add"
onclick="js:addRow()" />
&nbsp;
<input type="button" name="button3" id="button4" value="Delete"
onclick="js:removeRow()" />
</td>
</tr>

解决方案 »

  1.   

    首先 :不是 s:iterator中有重复数据,而是它迭代的容器中有数据;
    如果你的容器是 List , 它里面是可以有重复数据的 ,
    要想数据不重复,建议用 Set 。 
      

  2.   

    页面使用<s:if />标签当前记录一前一天比,如果相同,就不显示,否则就显示。
      

  3.   

    我在子窗口中加了一下判断。function addRow() {
    var uri = "adminUGMemberSelect";
    var rtnValue = window.showModalDialog(uri);
    if (rtnValue) {
    //add by:sc_zhang 2011-4-25
    var postIds = document.getElementsByName("postIds");
    var values;
    values = rtnValue.split(",");
    if (postIds.length != 0) {
    for ( var i = 0; i < postIds.length; i++) {
    if (postIds[i].value == values[0]) {
    alert("Current Member已经存在,不能重复添加!");
    return;
    }
    }
    }
    executeAddRow();
    parseReturnValue(rtnValue, detailRow - 1);
    }
    //fo.action="adminUGMember";
    }