• 使用JS传递数组型数据回服务器


    //为数组添加一个方法,判断某个值是否存在于数组中
    Array.prototype.in_array = function (e) {
    for (i = 0; i < this.length && this[i] != e; i++);
    return !(i == this.length);
    }
    var array = new Array();
    
    //数组中的Item
    var arr = {
    //"RFQID": $("#ID").val(),
    "RFQID": $(this).attr("rfqid"),
    "SiteCode": $(this).attr("site"),
    "ProcessID": $(this).attr("processid"),
    "ForecastLoading": $(this).val(),
    "SimulateNumber": 2,
    "MainRFQID": $("#ID").val()
    }
    
    array .push(arr); //将Item塞入数组
    $.ajax({
                        type: "Post",
                        processData: false,
                        contentType: 'application/json; charset=UTF-8',
                        url: "/ReportSimulation/UpdateProcessForecastLoading",
                        data: { list: arrObj },
                        beforeSend: function (xhr, setting) {
                            setting.data = JSON.stringify(setting.data);//转为Json
                        },
                        success: function (r) {
                            if (r.Success) {
                                alert("Success");
                            } else {
                                alert("Error");
                            }
                        }
                    });

    服务器接收:

    public ActionResult UpdateProcessForecastLoading(List<ForecastProcessLoadingVM> list)

    ForecastProcessLoadingVM 申明:

     public class ForecastProcessLoadingVM
        {
            public Guid RFQID { get; set; }
            public string SiteCode { get; set; }
            public Guid ProcessID { get; set; }
            public string ProcessName { get; set; }
            public double? ForecastLoading { get; set; }
            public int SimulateNumber { get; set; }
            public Guid MainRFQID { get; set; }
       }

    JQGrid中,直接将grid getRowData就可以传回了:

          var gridData = $gridCAPEX.getRowData();
                //var postData = JSON.stringify(gridData);
                //alert("JSON serialized jqGrid data:
    " + postData);
    
                var data = {
                    ID: $("#ID").val(),
                    NeedNewCAPEX: $("#NeedNewCAPEX").val(),
                    CAPEXVMList: gridData
                };
    
    
                $.ajax({
                    type: "Post",
                    processData: false,
                    contentType: 'application/json; charset=UTF-8',
                    url: "/BDFormPage/SaveCAPEX",
                    data: data,
                    beforeSend: function (xhr, setting) {
                        setting.data = JSON.stringify(setting.data);
                    },
                    success: function (r) {
                        if (r.Success) {
                            alert("Success");
                        } else {
                            alert("Error");
                        }
                    }
                });

     注意:getRowData取的是innerHtml,针对Select类型的选项,一定要将其格式也设置为Select,否则会传回Text,不传回Value

    {
                            label: "Category", name: "Category", index: "Category", hidden: false, editable: true,
                            editrules: { required: true },
                            edittype: "select", formatter: "select", editoptions: {
                                value: { 1: "New", 2: "Existing" }
                            }
                        },

    加上

    formatter: "select",getRowData取出的是1 2,否则取出的是New Existing
  • 相关阅读:
    activiti并行和串行区别
    SpringMVC 封装返回结果对象
    maven基础
    activiti表
    SpringBoot进阶
    SpringBoot基础
    javascript ES6模块化
    Vuejs搜索下拉框
    Vuejs2.0 + bootstrap demo
    maven settings.xml
  • 原文地址:https://www.cnblogs.com/ceci/p/4329268.html
Copyright © 2020-2023  润新知