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

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

转载于:https://www.cnblogs.com/hbym/p/11059204.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值