Freemark+juqery 自动增加行并保存数据

 <!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>编辑代码表</title>
  <link rel="icon" href="favicon.ico" type="image/x-icon" />
  <#include "/WEB-INF/template/common/include.ftl">
  <#include "/WEB-INF/template/common/input_include.ftl">
  <script type="text/javascript">
   $(document).ready(function(){
    var tag=$("#tag");
    if(tag.val()==""){
    addRow('hideTable');
    }
   });
   function deleteMe(obj){
    $(obj).parent().parent().remove();
    orderRows();
   }
   function addRow(objid){
    var row=$("#"+objid).find("tr:first").clone();
    //var target=$(".listTable").find(".dataRow:last");
    var target=$(".datatable").find("tr:last");
    row.insertAfter(target);
    orderRows();
   }
   
   function orderRows(){
    $(".datatable").find("tr").each(function(index){
     var inputs=$(this).find("input");
     for(var i=0;i<inputs.length;i++){
      var input=inputs[i];
      var name=input.name;
      var leftIdx=name.indexOf("[");
      var rightIdx=name.indexOf("]");
      var left=name.substring(0,leftIdx+1);
      var right=name.substring(rightIdx);
      input.name=left+(index-1)+right;
     }
    });
   }
  </script>
  <#if systemDict.dictCode?exists>
   <#assign operator="update">
  <#else>
   <#assign operator="save">
  </#if>
 </head>
 <body class="input">
  <div class="body" style="width:95%">
  <form id="inputForm" class="validate" action="system_dict!${operator}.action" method="post">
      <input type="hidden" name="id" id="tag" value="${systemDict.dictCodeId}"/>
      <input type="hidden" name="systemDict.dictCodeId" value="${systemDict.dictCodeId}"/>
      <input type="hidden" name="systemDict.systemDictCategory.dictCodeCategoryId" value="<#if systemDict.systemDictCategory??>${systemDict.systemDictCategory.dictCodeCategoryId}</#if>" >
   <ul class="tab">
    <li>
     <input type="button" value="c" hidefocus="true" />
    </li>
   </ul>
   <div class="tabContent">
    <table class="inputTable">                   
         <tr class="datarow">  <#-- class="listTable inputTable" -->
          <td colspan="2">
           <table class="datatable">
                         <#--<tr class="dataRow"> -->
                         <tr>
          <th width="35%">a</th>
          <th width="35%">b</th>
          <th width="20%">c</th>
          <th width="10%">操作</th>
         </tr>
         <#list values as list>
         <tr>
          <td>
           <input type="text" class="formText {required:true}" name="values[${list_index}].dictCodeText" value="${list.dictCodeText}"/>
           <label class="requireField">*</label>
          </td>
          <td>
           <input type="text" class="formText {required:true}" name="values[${list_index}].dictCodeValue" value="${list.dictCodeValue}"/>
           <label class="requireField">*</label>
          </td>
          <td>
           <input type="text"  class="formText" name="values[${list_index}].dictCodeValueIndex" value="${list.dictCodeValueIndex}"/>
          </td>
          <td align="center">
           <a href="javascript:;" οnclick="deleteMe(this)"><img src="${base}/static/admin/images/input_delete_icon.gif"/></a>
          </td>
         </tr>
         </#list>
                        </table>
          </td>
         </tr>             
                    </table>
                   
                    
                <div class="buttonArea">
      <div class="delBtn">
       <input type="button" <#if id?exists=false>disabled="true"</#if> class="formButton" οnclick="window.location='system_dict!delete.action?ids=${systemDict.dictCodeId}'" value="删 除" hidefocus="true" />
      </div>
      <div class="operBtn">
       <input type="button" οnclick="addRow('hideTable');" value="添加行" hidefocus="true" class="formButton"/>&nbsp;&nbsp;&nbsp;&nbsp;
       <input type="submit" value="保    存" hidefocus="true"  class="formButton"/>&nbsp;&nbsp;&nbsp;&nbsp;
       <input type="button" οnclick="window.location='system_dict!list.action?id=${systemDict.systemDictCategory.dictCodeCategoryId}'"  class="formButton" value="返  回" />
      </div>
     </div>
    </div>
   </form>
  </div>
 
  <table id="hideTable" style="display:none">
   <tr>
    <td>
     <input type="text" class="formText {required:true}" name="values[0].dictCodeText" style="width:80%"/>
     <label class="requireField">*</label>
    </td>
    <td>
     <input type="text" class="formText {required:true}" name="values[0].dictCodeValue" style="width:80%"/>
     <label class="requireField">*</label>
    </td>
    <td>
     <input type="text" class="formText {digits:true}" name="values[0].dictCodeValueIndex" style="width:80%"/>
    </td>
    <td align="center">
     <a href="javascript:;" οnclick="deleteMe(this)"><img src="${base}/static/admin/images/input_delete_icon.gif"/></a>
     <#-- <input type="button" value="删除" class="formButton"  οnclick="javascript:deleteMe(this)"/> -->
    </td>
   </tr>
  </table>
 </body>
</html>
 后台:

//保存代码表值

public void saveSystemDict(SystemDict sd, List<SystemDictValue> values) {
  systemDictDao.save(sd);
  for(SystemDictValue sdv:values){
   sdv.setSystemDict(sd);
   systemDictValueDao.save(sdv);
  }
 }

//action


 private List<SystemDictValue> values = new ArrayList<SystemDictValue>(); //代码表值

public String save(){
  systemDict.setCreateDate(new Date());
  systemDictService.saveSystemDict(systemDict, values);
  id = systemDict.getSystemDictCategory().getDictCodeCategoryId();
  this.redirectionUrl = "system_dict!list.action?id="+id;
  return SUCCESS;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值