后台获取jsp数组方法

来源:互联网 发布:mysql employees 编辑:程序博客网 时间:2024/06/05 05:26

jsp:EasyUi  的grid多选拼接数组

function getSelectedArr() {    var ids = [];    var rows = grid.datagrid('getSelections');    for (var i = 0; i < rows.length; i++) {        ids.push(rows[i].resId+"-"+rows[i].personId+"-"+rows[i].orgId);    }    return ids;}
function editSome() {var access = $('#access').val();if(access!='0'){    var rows = grid.datagrid('getSelections');    var num = rows.length;    if (num == 0 || num == 1) {        $.messager.alert('提示', '请选择至少两条记录进行操作!', 'info');        return;    } else{    accessData = getAccessInfo(rows[0].orgId,access);    if(accessData.flag==2){    return false;    }    var arr = getSelectedArr();    var url = baseURL+'modifySomeEquip.htm?arr='+arr;    if($('#eidt-window').has('iframe')){    $('iframe').remove();    }    $('#eidt-window').append('<iframe src="'+url+'" width="100%" height="100%" frameborder="no"></iframe>');    win = $('#eidt-window').window({    title:'编辑窗口',        closed: true,        modal: true,        shadow: false    });        win.window('open');    }}else{$.messager.alert('提示', '您不可以对此进行操作!', 'info');}}


后台:解析获取数组

@Overridepublic boolean updateEquipPerson(IMap param) {String[] arr = param.getString("arr").split(",");int personId = Integer.parseInt((String) param.get("personId"));String personCode = param.getString("personCode");param = parseArr(arr);param.put("personId", personId);param.put("personCode", personCode);int i = equipMaintainMapper.updateBySomeResId(param);boolean flag = false;if(i != 0){flag = true;}return flag;}private IMap parseArr(String[] arr) {List<String> personIdList = new ArrayList<String>();List<String> resList = new ArrayList<String>();for(int i=0; i<arr.length; i++){String[] id =arr[i].split("-");String resId = id[0];String personId = id[1];resList.add(resId);personIdList.add(personId);}IMap param = new IMap();param.put("resList", resList);param.put("personIdList", personIdList);return param;}

或者

jsp:

//工作内容function getContent(){var editRow = undefined;var workClass = document.getElementsByName("workClass");var obj = document.getElementsByName("dutyUnit");check_val = [];check_val2 = [];for (var i = 0; i < obj.length; i++) {if(obj[i].checked){check_val.push(obj[i].value);}}for (var i = 0; i < workClass.length; i++) {if(workClass[i].checked){check_val2.push(workClass[i].value);}}workInfo = $('#workContent').datagrid({// fit: true,        width: 'auto',        nowrap: false,          striped: true,          border: true,          collapsible:false,//是否可折叠的          fitColumns: true,//自动大小          loadMsg:'数据加载中...',        remoteSort:false,           idField:'id',          pagination:true,//分页控件          rownumbers:true,//行号          singleSelect:true,        queryParams:{"dutyUnit":check_val,"workClass":check_val2},        singleSelect:false,//是否单选          url: processURL + 'workContent.json',        columns: [[{field: 'ck',checkbox:true},{title: 'id', field: 'id', width:100,hidden:true},            {title: '工作大类', field: 'workClass', width:100,sortable: true},            {title: '工作项目', field: 'workContent', width:100,sortable: true },            {title: '工作标准', field: 'workStandard', width:100,sortable: true },            {title: '执行结果', field: 'resultFlag', width:300,hidden: true},             {title: '分值', field: 'workScore', width:50,align: 'center',sortable: true },            {title: '计量数量', field: 'workNumber', width:50,sortable: true ,align: 'center', editor: { type: 'numberbox', options: {min:0} } },            {title: '计量单位', field: 'measureUnit', width:50,align: 'center',sortable: true },            {title: '考核分值(默认为0)', field: 'examScore', width:80,sortable: true },            {title: '实际得分', field: 'actualScore', width:50,sortable: true },            {title: '考核原因(内容不可包含“-”)', field: 'examReason', width:120,sortable: true ,align: 'center', editor: { type: 'text', options: { required: true } } },            //{title: '执行人',field: 'executorId', width: 100, sortable: true , align: 'center', editor: { type: 'combobox', options: { data: executorList, valueField: "value", textField: "text"} },            //formatter:function(value,row,index){                //        for(var i=0; i<executorList.length; i++){                //            if (executorList[i].value == value){                //                return executorList[i].text;                //            }                //        }                //    }                //},                {title: '执行人', field: 'executorId', width:100,sortable: true,align: 'center',             formatter:resultType            }        ]],        onAfterEdit: function (rowIndex, rowData, changes) {        $('#'+rowData.id+'_select').val($('#executorValue').val()); editRow = undefined;},onDblClickRow: function (rowIndex, rowData) {$('#executorValue').val($('#'+rowData.id+'_select').val());if (editRow != undefined) {$("#workContent").datagrid('endEdit', editRow);}if (editRow == undefined) {$("#workContent").datagrid('beginEdit', rowIndex);editRow = rowIndex;}},onClickRow: function (rowIndex, rowData) {if (editRow != undefined) {$("#workContent").datagrid('endEdit', editRow);}}});}
后台:

@Overridepublic PageView getWorkContent(PageView pageView,IMap params) {params.put("paging", pageView);String[]  dutyUnit = (String[]) params.getValues("dutyUnit[]");String[]  workClass = (String[]) params.getValues("workClass[]");List<String> typeIdList = new ArrayList<String>();List<String> dataIdList = new ArrayList<String>();if(dutyUnit != null){for(int i=0;i<dutyUnit.length;i++ ){typeIdList.add(dutyUnit[i]);}}if(workClass != null){for(int i=0;i<workClass.length;i++ ){dataIdList.add(workClass[i]);}}if(typeIdList.size()>0 && dataIdList.size()>0){params.put("typeId", typeIdList);params.put("dataId", dataIdList);List<DutyProcess> list = dutyProcessMapper.queryWorkContent(params);pageView.setRows(list);}else{List<DutyProcess> list = new ArrayList<DutyProcess>();pageView.setRows(list);}return pageView;}

// 本方法只能用于从页面获取数组,例如相同名字的checkboxpublic String[] getValues(Object key) {return request == null ? null : request.getParameterValues((String) key);}


0 0
原创粉丝点击