单项处理
单项(单行)处理时,只需将数据行的主键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]));
}
}