• json使用


    <script type="text/javascript">
    $(function () {
      selectChange();
    })
    
    function selectChange() {
      var typeid = $("#protype").val();
      var product = $("#ProductInfo1_product").val();
    
      $.ajax({
        type: "post",
        url: "../PageService/ProductDataContentService.aspx?method=getParameter",
        dataType: "json",
        data: { "typeid": typeid,
        "Taskid": $("#taskid").val(),
        "demandid": $("#demandid").val(),
        "product": product
      },
      success: function (data) {
        //alert(data);
        var json = eval(data);
        var jcontent = "";
        var aTitle = Array();
        var aCont = Array();
        var i = 0;
        var n = 0;
        $.each(json, function (index, item) {
        //循环获取数据
          if (n % 12 == 0 && n != 0) { i++; }
            n++;
            aTitle[i] += "<th class='center'>" + item.name + "</th>";
            if (item.value == "nullnull") {
                aCont[i] += "<td class='center'>" + item.value + "</td>";
          } else {
              aCont[i] += "<td class='center'><input type='text' data='" + item.id + "' class='span1' value='" + item.value + "' /></td>";
          }
        });
        for (var j = 0; j < aTitle.length; j++) {
          jcontent += "<thead><tr>" + aTitle[j] + "</tr></thead><tbody><tr>" + aCont[j] + "</tr></tbody>";
        }
    
        $("#productC").empty().append(jcontent);
      },
      error: function () {
      alert("<%=Resources.global1.fail_load %>");
      }
    });
    }
    
    
    function save() {
      var jsonArr = [];
      $("#productC tbody input").each(function (i, n) {
      var jsonObj = {
      id: $(n).attr("data"),
        value: $(n).val()
      }
      jsonArr.push(jsonObj);
    });
    var strJson = arrayToJson(jsonArr);
    //alert(strJson);
    
      $.ajax({
        type: "POST",
        url: "../PageService/ProductDataContentService.aspx?method=save",
        data: {
          "json": strJson,
          "Taskid": $("#taskid").val(),
          "DemandsId": $("#demandid").val(),
          "ServiceNo": $("#ProductInfo1_serviceno").val(),
          "protype": $("#protype").val(),
          "product": $("#ProductInfo1_product").val()
         },
          dataType: "json",
          success: function (data) {
          alert(data.msg);
        }
      });
    }
    
    
    
    
    function arrayToJson(o) {
    var r = [];
    if (typeof o == "string") return """ + o.replace(/(['"\])/g, "\$1").replace(/(
    )/g, "\n").replace(/(
    )/g, "\r").replace(/(	)/g, "\t") + """;
    if (typeof o == "object") {
    if (!o.sort) {
    for (var i in o) r.push(i + ":" + arrayToJson(o[i]));
    if (!!document.all && !/^
    ?functions*toString()s*{
    ?s*[native code]
    ?s*}
    ?s*$/.test(o.toString)) {
    r.push("toString:" + o.toString.toString());
    }
    r = "{" + r.join() + "}";
    } else {
    for (var i = 0; i < o.length; i++) {
    r.push(arrayToJson(o[i]));
    }
    r = "[" + r.join() + "]";
    }
    return r;
    }
    return o.toString();
    }
    </script>
    
    
    
    
    
    /// <summary>
    /// 获取产品类型参数和收集产品信息 整合
    /// </summary>
    public void getParameter() 
    {
    JavaScriptSerializer Serializer = new JavaScriptSerializer();
    BaseClass.Common common = new BaseClass.Common();
    Dictionary<string, string> dProtParam=common.GetProTypeParam(protype);
    
    
    ProducDataContentInfo pinfo = new ProducDataContentInfo();
    IList<ProducDataContentInfo> list=poperate.GetList(1,1,string.Format(" and taskId={0} and DemandsId={1} and ProductType='{2}' and ProductSerialNumber='{3}'",taskId,demandId,protype,productCode),"id desc"," id asc");
    IList<productTypeParam> ptplist=new List<productTypeParam>();
    if (list.Count > 0)
    {
    pinfo = list[0];
    IList<productTypeParam> pTypeP = Serializer.Deserialize(pinfo.ProductContent, typeof(IList<productTypeParam>)) as IList<productTypeParam>;
    foreach (productTypeParam ptp in pTypeP)
    {
    if (dProtParam.ContainsKey(ptp.id.ToString()))
    {
    ptp.name = dProtParam[ptp.id.ToString()];
    ptplist.Add(ptp);
    }
    }
    }
    else {
    productTypeParam ptp = null;
    foreach (KeyValuePair<string, string> k in dProtParam) 
    {
    ptp = new productTypeParam();
    ptp.id = k.Key;
    ptp.name = k.Value;
    ptp.value = "nullnull";
    ptplist.Add(ptp);
    }
    }
    string jsonData = Serializer.Serialize(ptplist);
    System.Web.HttpContext.Current.Response.Write(jsonData);
    }
  • 相关阅读:
    选择 冒泡 快速 插入排序
    类方法
    Java--静态区域块
    打印字母如何显示声调
    navicat 创建的表,username字段不能接受中文名字。
    C++primer plus第六版课后编程题答案10.8(来个高手教教我)
    C++primer plus第六版课后编程题答案10.7
    C++primer plus第六版课后编程题答案10.6
    错误 1 error C2143: 语法错误 : 缺少“;”(在“using”的前面)
    C++primer plus第六版课后编程题答案10.5
  • 原文地址:https://www.cnblogs.com/jcz1206/p/3983142.html
Copyright © 2020-2023  润新知