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";
}

本人菜鳥,貼出來是為了方便自己以后使用,如有不對的多多指教啊。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM