表单的单项处理与批量处理操作

在这里插入图片描述

单项处理

单项(单行)处理时,只需将数据行的主键id值作为入参传入处理函数即可。需要注意的是,添加c:if判断以避免重复处理。

<td class="center">
	<c:if test="${item.approvalStatus == 'INITIAL'}">
		<a class="btn btn-xs btn-success review" title="审核" οnclick="review('${item.id}');">
			<i class="ace-icon fa fa-pencil-square-o" title="审核"></i>
		</a>
	</c:if>
	<c:if test="${item.approvalStatus != 'INITIAL'}">
		已审核
	</c:if>
</td>

通过javaScript获取批量选择的id值。

![2021041303](F:\XWSoftProjects\工作记录\知识点记录\img\2021041303.jpg)function review(id){
    top.jzts();
    var ids = [id];  // 为了后端统一处理,单行处理和批量处理都将id值装入数组。
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title = "模式审核";
    diag.URL = '<%=basePath%>export/example.do?ids=' + ids;
    diag.Width = 469;
    diag.Height = 170;
    diag.CancelEvent = function () { //关闭事件
      diag.close();
      window.location.reload();  // 刷新页面
    };
    diag.show();
}
// 获取Id List
function getIds () {
	var tds = $('.td-checkbox')
	var ret = []
    tds.each(function (index, item) {
    	if (item.checked) {
        	ret.push($(item).val())
        }
    })
    return ret
}
批量处理

表单中添加复选框列,点击checkbox后,通过“批量处理”按钮调用js函数进行批量处理。需要注意的是,可以通过c:if判断,让符合条件的(如:未处理)数据显示checkbox,避免重复处理。

<c:forEach items="${applicationList}" var="item" varStatus="pd">
    <tr>
        <c:if test="${item.approvalStatus == 'INITIAL'}">
        <td class='center' style="width: 30px;">
            <input type="checkbox" value="${item.id}" class="td-checkbox" />  // 添加class"td-checkbox"便于js定位
        </td>
        </c:if>
    </tr>
</c:forEach>

通过javaScript获取批量选择的id值。

function batchReview() {
  var ids = getIds();
  if(ids.length == 0){
    alert("请选择要批量审核的数据行!");
  }else {
    diag.URL = '<%=basePath%>goExample.do?ids=' + ids;
    diag.CancelEvent = function () { //关闭事件
      diag.close();
      window.location.reload();  // 刷新页面
    };
    diag.show();
  }
}
Controller方法
public ModelAndView example(Page page) throws Exception {
    	// 通过逗号切分,存入String数组
        String[] ids = pd.getString("ids").split(",");
    	// 因为需要转为List<Long>
        List<Long> Ids = new ArrayList();
        for (int i = 0; i < ids.length; i++) {
            Ids.add(Long.parseLong(ids[i]));
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴翔的技术博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值