残缺丶 2015-06-01 07:19 采纳率: 56%
浏览 1709

我需要把一张表以easyui树的形式显示,求教

我需要把一张表以easyui树的形式显示,这张表有parentID,看下图图片说明
前台我是这样写的:

 jQuery(function() {
           $('#tree').tree({
               url: '../Handlers/ECTree.ashx',
               method: 'get',
               animate: true,
               loadFilter: function (data) { 
                   alert(data);
                   if (data.d) {
                       return data.d;
                   } else { 
                       return data;
                   }
               }
           });
       });

后台一般处理文件是这样写的,我已拿到该表的实体对象,需要拼接成Tree能识别的json格式的数据,该怎么写呢?

  public void ProcessRequest(HttpContext context)
        {
            StringBuilder stringBuilder = new StringBuilder();
            IList<EC> ec = ECBLL.GetList();
            foreach (EC row in ec)
            {

                stringBuilder.Append("[{");
                stringBuilder.Append("\"id\":\"" + row.ECID+"\",");
                stringBuilder.Append("\"text\":\"" + row.ECName+"\",");
                stringBuilder.Append("\"children\":\"" +row.ParentID); 
                stringBuilder.Append("}]");
            }
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string jsons = jss.Serialize(stringBuilder);
            context.Response.Write(jsons);
        }
  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2015-06-01 07:23
    关注

    自己遍历生成下面类型的数据输出就行

    
    [{
        "id":1,
        "text":"My Documents",
        "children":[{
            "id":11,
            "text":"Photos",
            "state":"closed",
            "children":[{
                "id":111,
                "text":"Friend"
            },{
                "id":112,
                "text":"Wife"
            },{
                "id":113,
                "text":"Company"
            }]
        },{
            "id":12,
            "text":"Program Files",
            "children":[{
                "id":121,
                "text":"Intel"
            },{
                "id":122,
                "text":"Java",
                "attributes":{
                    "p1":"Custom Attribute1",
                    "p2":"Custom Attribute2"
                }
            },{
                "id":123,
                "text":"Microsoft Office"
            },{
                "id":124,
                "text":"Games",
                "checked":true
            }]
        },{
            "id":13,
            "text":"index.html"
        },{
            "id":14,
            "text":"about.html"
        },{
            "id":15,
            "text":"welcome.html"
        }]
    }]
    
    
    评论

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败