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);

转载于:https://www.cnblogs.com/allen0118/p/4403119.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值