• 使用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
  • 相关阅读:
    js --- for in 和 for of
    vue -- config index.js 配置文件详解
    vue -- 脚手架之webpack.dev.conf.js
    vue --- 解读vue的中webpack.base.config.js
    vue 引入第三方字体包
    js call 和 apply
    vue2.0中的$router 和 $route的区别
    懒加载js实现和优化
    vue的指令在webstrom下报错
    BFC的布局规则和触发条件
  • 原文地址:https://www.cnblogs.com/ceci/p/4329268.html
Copyright © 2020-2023  润新知