簡體   English   中英

如何在Struts 2中將一個表的內容轉移到另一個表?

[英]How to transfer contents of one table to another in struts 2?

我有兩個表顯示兩個列表。 這是我的jsp

<%@page  contentType="text/html;charset=UTF-8"language="java"pageEncoding="UTF-8"%>
<%@taglib prefix="s"uri="/struts-tags"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Insert title here</title>

</head>
<body>
<s:form name="tableForm"method="post">
<th>
<s:submit action="verify" key="Add"></s:submit>

</th>
<table id="one">
<thead>
<tr>
<th ></th>
<th> Id</th>
<th>Name</th>
<th>Status</th>
<th>Type</th>
<th>RollUp Type</th>
<th>System</th>
</tr>
</thead>
    <tbody>
    <s:iterator value="formList1">
        <tr>
        <td><s:checkbox name="checked" fieldValue="%{#attr.ID}" theme="simple" ></s:checkbox>
</td>
<td><s:property value="ID"/></td>
<td><s:property value="NAME"/></td>
<td><s:property value="STATUS"/></td>
<td><s:property value="TYPE"/></td>
<td><s:property value="ROLLUPTYPE"/></td>
<td><s:property value="UNIT"/></td>

        </tr>
        </s:iterator>
     </tbody>
</table>

<table id="two">
<thead>
<tr>
<th ></th>
<th> Id</th>
<th>Name</th>
<th>Status</th>
<th>Type</th>
<th>RollUp Type</th>
<th>System</th>
</tr>
</thead>
    <tbody>
    <s:iterator value="formList2">
        <tr>
        <td><s:checkbox name="checked" fieldValue="%{#attr.ID}" theme="simple" ></s:checkbox>
</td>
<td><s:property value="ID"/></td>
<td><s:property value="NAME"/></td>
<td><s:property value="STATUS"/></td>
<td><s:property value="TYPE"/></td>
<td><s:property value="ROLLUPTYPE"/></td>
<td><s:property value="UNIT"/></td>

        </tr>
        </s:iterator>
    </tbody>

</table>
<s:a href="#" id="add">add &gt;&gt;</s:a>
    <s:a href="#" id="remove">&lt;&lt; remove</s:a>
</s:form >
</body>
</html>

在這里,當我單擊添加時,我想將從表1選中的行移至表2,同樣,當我單擊刪除時,將從表2選中的行移至表1。 我在此鏈接http://jsfiddle.net/AkVTw/1/上找到了類似的示例,但在我的jsp中無法解決。

如果您可以建議我一些使用jQuery / javascript實現此功能的示例代碼,那將非常有幫助

我也想知道是否可以在struts 2中使用s:optiontransferselect標記實現此功能?

您可以使用jquery輕松做到這一點。 jQuery具有此類型功能的“ appendTo”功能。

$(document).ready(function(){
  $('#add').on("click", function(){
      $('#one tbody input:checked').parent().parent().appendTo("#two tbody");
  });

  $('#remove').on("click", function(){
      $('#two tbody input:checked').parent().parent().appendTo("#one tbody");
  });
});

我創建了演示鏈接 你可以測試一下。

如果您只想克隆已檢查的行並將其保留在表1中,同時將它們移至表2中,則可以使用.clone(),或者如果您希望將它們從第一個表中移走並移至第二個表您可以使用appendTo(); jsfiddle: http : //jsfiddle.net/eFaca/

$("#addRows").click(function(){
$("#table").find("input:checked").closest("tr").appendTo("#table2");
});
$("#removeRows").click(function(){
$("#table2").find("input:checked").closest("tr").appendTo("#table");
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM