js 集合对象应用

定义[] js集合

注: 以隐藏域形式传入后端,这样可以解决多个id值拼接传参问题后端String 类型封装数据,mybatis转成数组的形式便于foreach
js 集合对象应用_第1张图片

   var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        var rlmcArray = [],clnfArray = [],fdjxhArray= [],cxmcArray=[];
        if(rows && rows.length > 0){
            for(var index in rows){
                if(rows[index].rlmc){
                    if(!rlmcArray[rows[index].rlmc]){
                        rlmcArray.push(rows[index].rlmc)
                    }
                }
                if(rows[index].clnf){
                    if(!clnfArray[rows[index].clnf]){
                        clnfArray.push(rows[index].clnf)
                    }
                }
                if(rows[index].cxmc){
                    if(!cxmcArray[rows[index].cxmc]){
                        cxmcArray.push(rows[index].cxmc)
                    }
                }
                if(rows[index].fdjxh){
                    if(!cxmcArray[rows[index].fdjxh]){
                        fdjxhArray.push(rows[index].fdjxh)
                    }
                }

            }
        }

        $("#fdjxhString").val(fdjxhArray.join(","));

mybaits sql 如下

js 集合对象应用_第2张图片

js 对象 前端如何json形式传参
var lld = {};
		//领料单
		lld.list = datas;
		lld.lldid = $("#bizId").val();
		lld.lldh = $("#lldh").val();
		lld.llrid = $("#llrid").val();

JSON.stringify(saveData) 这样可以转换json 字符串 ,data 是一个list
后端可以用JSONObject.parseObject 转换为后端的list
例: 1.前端以集合形式传参
JSONObject djyj = JSONObject.parseObject(txcljcdjvar);
List List = JSONObject.parseArray(djyj.getString(“list”), ScglScfl.class);
2.前端以object形式传参
TlrkSubmit tlrkSubmit = JSONObject.parseObject(data, TlrkSubmit.class);

集合的其他用法

遍历集合 返回一个option

   			if (rList[tempRlmc]) {
                    let zccs = rList[tempRlmc][0] + datas[index].zccs;
                    let ylcount = rList[tempRlmc][1] + datas[index].ylcount;
                    rList[tempRlmc]= [zccs,ylcount]
                }else {
                    rList[tempRlmc] = [datas[index].zccs,datas[index].ylcount];
                }
                
 Object.keys(cxList).forEach(function(key){
            let value = key  + "(" + cxList[key][0]+'/'+cxList[key][1]+")" ;
            if(cxmc == key){
                option1 = option1 + "";
            }else{
                option1 = option1 + "";
            }
        });
        $("#cxid").html(option1);

你可能感兴趣的:(js)