BootStrap table 用List做参数传值,前后端的处理

BootStrap table 用List做参数传值,前后端的处理

前端:
// 获取选中并写入数据的数据行,写入下一个页面
if (trs.size() > 0) {
for (var i = 0; i < trs.size(); i++) {
if (trs[i].cells[0].children[0].firstElementChild.firstChild.checked &&
Number(trs[i].cells[6].children[0].value) > 0
) {

            var od = {
                workorderCode:workorderCode,
                whseCode:trs[i].cells[1].innerHTML,
                channelClientNbr: trs[i].cells[2].innerHTML,
                locnCode:trs[i].cells[3].innerHTML,
                needQty: trs[i].cells[6].children[0].value
            }
            list.push(od);
        }
    }
}


if (list.length > 0) {
    $.ajax({
        url: prefix + "/saveBomParts.bee",
        type: "post",
        data:{"list":JSON.stringify(list)},
        //发送方式改为同步,避免弹出页面被浏览器拦截
        async: false,
        success: function (r) {
            if (r.code == 0) {
                layer.msg(r.msg);

            } else {
                layer.msg(r.msg);
            }
        }
    });

后端:

片段1:

@RequestMapping("/saveBomParts")
@ResponseBody
public Map saveBomParts(@RequestParam("list") String list, HttpServletRequest request){
    JSONArray array = (JSONArray) JSONArray.parse(list);
    Map map = bomOrderDtlService.save(array,request);
    return map;
}

片段2:

for (Object o : array) {
BomOrderDtl bomOrderDtl = new BomOrderDtl();
workorderCode = (String) ((JSONObject) o).get(“workorderCode”);
orderNum = “BOM” + workorderCode.substring(2, workorderCode.length());

        String _locnCode = (String) ((JSONObject) o).get("locnCode");
        _whseCode = (String) ((JSONObject) o).get("whseCode");
        String _skuCode = (String) ((JSONObject) o).get("skuCode");
        String _needQty = (String) ((JSONObject) o).get("needQty");

        PickLocn pickLocn =  pickLocnService.pickLocnsDtl(_locnCode,_whseCode,_skuCode);

关键

1.前端使用 JSON.stringify(list)
2.后端
@RequestParam(“list”) String list,
JSONArray array = (JSONArray) JSONArray.parse(list),
String _locnCode = (String) ((JSONObject) o).get(“locnCode”);

你可能感兴趣的:(BootStrap)