zoukankan      html  css  js  c++  java
  • 使用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
  • 相关阅读:
    scp远程文件传输
    ssh远程登录
    PHP PDO使用
    Linux引导流程
    Samba服务器搭建
    linux ftp服务器搭建
    NfS服务的搭建
    Discuz! X2.5数据库字典【转载】
    javaSctipt基础
    压缩文件 compress files 以7z 格式及解压 或者别的格式
  • 原文地址:https://www.cnblogs.com/ceci/p/4329268.html
Copyright © 2011-2022 走看看