zoukankan      html  css  js  c++  java
  • JavaScript 拼接JSON

        <script language="javascript" type="text/javascript">
            var json="";
            $(document).ready(function () {
                $("#Button1").bind("click", function () {
                    $.ajax({
                        type: "post",
                        url: "GiftBox_RePrint.aspx?Oper=load_templateslist&key=" + Math.round(),
                        dataType: "text",
                        cache: false,
                        success: function (data) {
                            var arr_temp_list = new Array(); //返回的全部数据
    
                            var arr_temp_id = new Array(); //保存所有的模板ID
                            var arr_temp_name = new Array(); //保存所有的模板名称
                            arr_temp_list = data.split(","); //根据逗号拆分,结果为ID:Name                        
                            json += "[";
                            for (i = 0; i < arr_temp_list.length; i++) {
                                arr_temp_id.push(arr_temp_list[i].substring(0, arr_temp_list[i].indexOf(":")));
                                arr_temp_name.push(arr_temp_list[i].substring(arr_temp_list[i].indexOf(":") + 1, 3000));
    
                                if (i > 0) {
                                    json += ",";
                                }
                                json += "{"LOT_ID":"" + arr_temp_id[i].toString() + "","LOT_NAME":"" + escape( arr_temp_name[i].toString()) + ""}";
                            }
                            json += "]";
                            $("#cmbTempList").combobox("loadData", json);
    
                        }
                    });               
    
                });
    
            });       
        </script>

     如果需要将此json绑定给控件 ,则还需要eval:

     json = eval("" + json + "");
    $("#cmbtest").combobox("loadData", json);

  • 相关阅读:
    Delphi播放铃声
    小技巧
    Delphi线程中使用waitfor返回值
    window安装、启动consul
    kali2020-bash: openvas-setup:未找到命令 ,解决办法
    zookeeper 客户端
    redis 集群
    activeMQ
    Shiro
    Eclipse Java注释模板设置详解
  • 原文地址:https://www.cnblogs.com/allen0118/p/4403119.html
Copyright © 2011-2022 走看看