适用于zTree 、EasyUI tree、EasyUI treegrid
?#region?
??????? System.Text.StringBuilder b_appline = new System.Text.StringBuilder();
??????? System.Text.StringBuilder b_children = new System.Text.StringBuilder();
??????? /// <summary>
??????? /// 適用于zTree 、EasyUI tree、EasyUI treegrid
??????? /// zTree設置id,name,EastyUI 設置 id,text EasyUI treegrid 可自定義
??????? /// </summary>
??????? /// <param name="Source">數(shù)據(jù)源</param>
??????? /// <param name="_parentidName">父級名稱</param>
??????? /// <param name="_parentidValue">父級頂級節(jié)點</param>
??????? /// <param name="Key">子節(jié)點(唯一值)</param>
??????? /// <returns></returns>
??????? public string GetTreeJson(DataTable Source, string _parentidName, string _parentidValue, string Key)
??????? {
??????????? try
??????????? {
??????????????? b_appline.Append(b_children.ToString());
??????????????? b_children.Clear();
??????????????? if (Source.Rows.Count > 0)
??????????????? {
??????????????????? b_children.Append("[");
??????????????????? DataRow[] row = Source.Select(string.Format("{0}='{1}'", _parentidName, _parentidValue));
??????????????????? if (row.Count() > 0)
??????????????????? {
??????????????????????? for (int i = 0; i < row.Count(); i++)
??????????????????????? {
??????????????????????????? b_children.Append("{");
??????????????????????????? for (int c = 0; c < Source.Columns.Count; c++)
??????????????????????????? {
??????????????????????????????? b_children.AppendFormat("\"{0}\":\"{1}\",", Source.Columns[c].ColumnName, row[i].ItemArray[c]);
??????????????????????????? }
??????????????????????????? b_children.Remove(b_children.Length - 1, 1);
??????????????????????????? if (Source.Select(string.Format("{0}='{1}'", _parentidName, row[i][Key].ToString())).Length > 0)
??????????????????????????? {
??????????????????????????????? b_children.Append(",\"children\":");
??????????????????????????????? GetTreeJson(Source, _parentidName,row[i][Key].ToString(), Key);
??????????????????????????????? b_appline.Append(b_children.ToString());
??????????????????????????????? b_children.Clear();
??????????????????????????? }
??????????????????????????? b_appline.Append(b_children.ToString());
??????????????????????????? b_children.Clear();
??????????????????????????? b_children.Append("},");
??????????????????????? }
??????????????????????? b_children.Remove(b_children.Length - 1, 1);
??????????????????? }
??????????????????? b_children.Append("]");
??????????????????? b_appline.Append(b_children.ToString());
??????????????????? b_children.Clear();
??????????????? }
??????????????? return b_appline.ToString();
??????????? }
??????????? catch (Exception)
??????????? {
??????????????? throw;
??????????? }
??????? }
??????? #endregion
轉載于:https://www.cnblogs.com/rancrazy/p/7612011.html
總結
以上是生活随笔為你收集整理的适用于zTree 、EasyUI tree、EasyUI treegrid的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL语言基础
- 下一篇: IP地址的网络位与主机位