码迷,mamicode.com
首页 > 数据库 > 详细

ztree + ashx +DataTable +Oracle

时间:2014-06-10 13:11:00      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   java   http   tar   

        好久没有使用ztree了,刚才在使用ztree做导航时遇到了几个小问题: 1、返回数据源是undefined 。 2、数据出现后树结构没有出现(pIdKey单词拼写错误).

 在使用Oracle查询时,Oracle将所有列名转化为大写,我在JSON处理过程中手动将字段处理成小写。

 js代码:    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script type="text/javascript">
        var selectNode; // ztree选中节点
        var treeObj;
        var settings = {
            data: {
                key: {
                    name: "name"
                },
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pid"
 
                }
            },
            callback: {
 
            }
        };
 
        function AjaxZtree() {
            $.ajax({
                type: ‘GET‘,
                url: ‘../Analysis/Handler/Tree.ashx?action=report‘,
                cache: true,
                async: false,
                dataType: "text",
                ContentType: "application/json; charset=utf-8",
                success: function (data) {
                    $.fn.zTree.init($("#ReportTree"), settings, (new Function(‘return‘ + data))());
                    treeObj = $.fn.zTree.getZTreeObj("ReportTree");
                },
                error: function () {
                    alert(‘Error‘);
                }
            });
        }
 
        $(document).ready(function () {
            AjaxZtree();
        });
    </script>

ashx代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request.QueryString["action"];
 
            if (action == "report")
            {
                var result = reportibll.ZtreeJSON();
                string json = ConvertJson.ToJson(result);
                context.Response.Write(json);
            }
            else
            {
                 
            }
 
             
        }

JSON处理代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public static string ToJson(DataTable dt)
       {
           StringBuilder jsonString = new StringBuilder();
           jsonString.Append("[");
           DataRowCollection drc = dt.Rows;
           for (int i = 0; i < drc.Count; i++)
           {
               jsonString.Append("{");
               for (int j = 0; j < dt.Columns.Count; j++)
               {
                   string strKey = dt.Columns[j].ColumnName.ToLower();
                   string strValue = drc[i][j].ToString();
                   Type type = dt.Columns[j].DataType;
                   jsonString.Append("\"" + strKey + "\":");
                   strValue = StringFormat(strValue, type);
                   if (j < dt.Columns.Count - 1)
                   {
                       jsonString.Append(strValue + ",");
                   }
                   else
                   {
                       jsonString.Append(strValue);
                   }
               }
               jsonString.Append("},");
           }
           jsonString.Remove(jsonString.Length - 1, 1);
           jsonString.Append("]");
           return jsonString.ToString();
       }

  

  

 

 

   

ztree + ashx +DataTable +Oracle,布布扣,bubuko.com

ztree + ashx +DataTable +Oracle

标签:class   blog   code   java   http   tar   

原文地址:http://www.cnblogs.com/sword-successful/p/3778318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!