js列表上实现向后台传输多个值

思路分析
要用单独的一个复选框选中后直接向后台传数据显然不合理(因为我的前台是一个foreach遍历开的一个列表,一次传输只能传递一个值),所以需要增加一个用于控制的按钮或者检测控制的按钮用来检测列表内的复选框哪些被选中

代码

    $("#exportTreeGrid").click(function(){
			alert('123');
			var id_array = new Array();
			$("input[id='checkId']:checked").each(function(){
				id_array.push($(this).val());
			});
			//alert(id_array);
			if(id_array.length == 0){
				alert('请您选择要导出的复选框');
				return ;
			}else{
				 top.$.jBox.confirm("确认要导出已经确认的数据吗?","系统提示",function(v,h,f){
 					if(v=="ok"){
						location.href="${ctx}/fdzapp/combineList/batchExport?combineCodes="+id_array;
 					}
	 				},{buttonsFocus:1});
	 				top.$('.jbox-body .jbox-icon').css('top','55px');
			}
		});



    $("#checkAll").click(function(){

			if(this.checked){
		        $("input[id='checkId']").attr("checked","checked");
		         var arrs=new Array();
		            $("input[id='checkId']:checked").each(function(){ 
		                if($(this).attr("checked")){
		                    arrs.push($(this).val());
		                }
		            });
					
		            if(arrs.length==0 ){
		                alert('请选择数据!');
		                return ;
		            }
		            var combineCodes = arrs;
		            //var combineCodes = arrs.join(",");
		            //alert(combineCodes);
						debugger;
		            top.$.jBox.confirm("确认要导出数据吗?","系统提示",function(v,h,f){
	 					if(v=="ok"){
							location.href="${ctx}/fdzapp/combineList/batchExport?combineCodes="+combineCodes;
	 					}
	 				},{buttonsFocus:1});
	 				top.$('.jbox-body .jbox-icon').css('top','55px');
		       // alert(ids);
		     }else{
		        $("input[id='checkId']").attr("checked",null);
		        
		     }
		});
		 
前台向后台传入的是字符串,后台取到后分隔就行了
    
    @RequiresPermissions("fdzapp:combineList:edit")
@RequestMapping(value = {"batchExport"})
public void batchExport(@RequestParam String combineCodes,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes){
System.err.println(combineCodes);
try {
	 String fileName = "合件明细数据"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
		if(StringUtils.isNotBlank(combineCodes)){
		    String[] staffIds = combineCodes.split(",");
		   List<CombineList> lists =  new ArrayList<CombineList>();
			 for (String combineCode1 : staffIds) {
				 String  combineCode = combineCode1.substring(0, combineCode1.length());
				 System.err.println(combineCode);
				 CombineList combineList =  new CombineList();
				 combineList.setCombineCode(combineCode);
				 combineList.setListStatus("4");
				// System.err.println(combineList.getCombineCode()+"输出看看");
				 List<CombineList> list = combineListService.find4CwBatchExport(combineList);
				 System.err.println(list.get(0).getComponentCode()+"12345678");
				 lists.addAll(list);
			 }
			if(lists.size() == 0) {//没取到值
	        	addMessage(redirectAttributes, "批量操作失败了!!!!");
	        	//return "redirect:" + Global.getAdminPath() + "/fdzapp/combineList/";
	        }else {
	        	new ExportExcel("合件明细数据", CombineList.class).setDataList(lists).write(response, fileName).dispose();
				//return null;
	        }
		}
} catch (Exception e) {
	addMessage(redirectAttributes, "数据导出失败!失败信息:"+e.getMessage());
}
  // return "modules/fdzapp/combineCostList_Cw";
}

本人菜鸟,贴出来是为了方便自己以后使用,如有不对的多多指教啊。。

posted @ 2019-06-20 15:50  堕落先锋  阅读(1327)  评论(0编辑  收藏  举报