C#将datatable生成easyui的绑定tree 的json数据格式
来源:互联网 发布:2017全国进出口数据 编辑:程序博客网 时间:2024/06/04 19:50
/// <summary>
/// 根据DataTable生成Json树结构
/// </summary>
/// <param name="tabel">数据源</param>
/// <param name="idCol">ID列</param>
/// <param name="txtCol">Text列</param>
/// <param name="rela">关系字段(字典表中的树结构字段)</param>
/// <param name="pId">父ID(0)</param>
StringBuilder result = new StringBuilder();
StringBuilder sb = new StringBuilder();
private void GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string rela, object pId)
{
result.Append(sb.ToString());
sb.Clear();
if (tabel.Rows.Count > 0)
{
sb.Append("[");
string filer = string.Format("{0}='{1}'", rela, pId);
DataRow[] rows = tabel.Select(filer);
if (rows.Length > 0)
{
foreach (DataRow row in rows)
{
sb.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"state\":\"open\"");
if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
{
sb.Append(",\"children\":");
GetTreeJsonByTable(tabel, idCol, txtCol, rela, row[idCol]);
result.Append(sb.ToString());
sb.Clear();
}
result.Append(sb.ToString());
sb.Clear();
sb.Append("},");
}
sb = sb.Remove(sb.Length - 1, 1);
}
sb.Append("]");
result.Append(sb.ToString());
sb.Clear();
}
}
GetTreeJsonByTable(datatable, "id", "title", "pid", "0");
string content = result.ToString();
- C#将datatable生成easyui的绑定tree 的json数据格式
- C#将datatable生成easyui的绑定tree 的json数据格式
- C#将datatable生成easyui的绑定tree 的json数据格式
- 生成EasyUI Tree所需的Json数据格式
- C#生成JSON数据格式的函数
- easyui tree 的数据格式转换
- easyUI tree数据格式的转换
- DataTable转为json并绑定Easyui的datagrid控件
- .net 生成 easyui tree树的json
- 生成符合EasyUI-Tree的JSON数据
- Asp.net生成Extjs-Tree数据格式的json类
- 用友U8存货分类通过DataTable生成EasyUI Tree JSON
- easyui tree 实现类似ztree的数据格式
- easyui tree 的异步加载 前台的编写方法和后台的json数据格式组装方法
- php生成easyUI Tree要用到的json格式
- C#将标准的Json转换DataTable源文件
- C# 将DataTable转换成ExtJS可用的Json格式
- easyui加载datagrid和treegrid的几种json数据格式
- android gradle include so libs
- A FLASH Bootloader for PIC16 and PIC18 Devices--硬译(五)
- C/C++ union用法(转)
- commons-fileupload和dwr实现带有进度条的文件上传
- 短语、直接短语、句柄、素短语
- C#将datatable生成easyui的绑定tree 的json数据格式
- struts框架中使用tiles组件代码实例
- hdu 1429搜索
- c# 使用FileStream打开并清空文件、将一文件内容另存为到新文件
- ImageButton组件的应用
- 大数据量采用什么方式建表
- typedef define
- URL编码
- 【JAVA 基础】JAVA常见异常集锦(持续更新)