• EasyUI TreeJson


    1. TreeJson

    str = GetTreeJsonByTable(dt, "id", "fid", "0");
          StringBuilder treeResult = new StringBuilder();
            StringBuilder treesb = new StringBuilder();
            public string GetTreeJsonByTable(DataTable tabel, string idCol, string rela, object pId)
            {
                string treeJson = string.Empty;
                treeResult.Append(treesb.ToString());
                treesb.Clear();
                if (tabel.Rows.Count > 0)
                {
                    treesb.Append("[");
    
                    string filer = string.Empty;
                    if (pId.ToString() == "")
                    {
                        filer = string.Format("{0} is null", rela);
                    }
                    else
                    {
                        filer = string.Format("{0}='{1}'", rela, pId);
                    }
                    DataRow[] rowtote = tabel.Select(filer);
                    if (rowtote.Length > 0)
                    {
                        //foreach (DataRow row in rows)
                        for (int i = 0; i < (rowtote.Length); i++)
                        {
                            treesb.Append("{");
                            for (int j = 0; j < tabel.Columns.Count; j++)
                            {
                                treesb.Append(""");
                                treesb.Append(tabel.Columns[j].ColumnName);
                                treesb.Append("":"");
                                treesb.Append(rowtote[i][j].ToString());
                                treesb.Append("",");
                            }
                            treesb.Remove(treesb.Length - 1, 1);
                            if (tabel.Select(string.Format("{0}='{1}'", rela, rowtote[i][idCol])).Length > 0)
                            {
                                treesb.Append(","children":");
                                GetTreeJsonByTable(tabel, idCol, rela, rowtote[i][idCol]);
                                treeResult.Append(treesb.ToString());
                                treesb.Clear();
                            }
                            treeResult.Append(treesb.ToString());
                            treesb.Clear();
                            treesb.Append("},");
                        }
                        treesb = treesb.Remove(treesb.Length - 1, 1);
                    }
                    treesb.Append("]");
                    treeResult.Append(treesb.ToString());
                    treeJson = treeResult.ToString();
                    treesb.Clear();
                }
                return treeJson;
            }
  • 相关阅读:
    Shiro理解与总结
    spark教程(14)-共享变量
    Hive 教程(十)-UDF
    multivariate_normal 多元正态分布
    windows 安装 python 踩坑记录
    EM 算法(三)-GMM
    EM 算法(二)-KMeans
    EM 算法(一)-原理
    sklearn-GDBT
    集成学习-Boosting 模型深度串讲
  • 原文地址:https://www.cnblogs.com/yimeishui/p/5902522.html
Copyright © 2020-2023  润新知