• ASP.NET框架获取数据字典数据做成树的格式


         private List<TreeEntity> treeList = new List<TreeEntity>();//创建一个树的List集合
         public ActionResult GetTree1Json(string id)
            { 
                var root = new DataItemBLL().GetEntity(id);//树的根节点
                TreeEntity tree = new TreeEntity();//创建一个树的实体对象
                tree.id = root.ItemId;//根节点树的ID
                tree.text = root.ItemName;//根节点要在前端显示的内容
                tree.value = root.ItemCode;//根节点的值
                tree.isexpand = true;//是否需要展开
                tree.complete = true;
                tree.hasChildren = true;//是否还有子节点
                tree.parentId = "0";//根节点的父ID必须为0才会显示
                treeList.Add(tree);//把树放到树的List集合里面去
                set(id);
                void set(string ia) {//以此类推
                    var datalist = messagesendbll.GetDataList(ia);
                    foreach (DataItemEntity die in datalist)
                    {
                        tree = new TreeEntity();
                        tree.id = die.ItemId;
                        tree.text = die.ItemName;
                        tree.showcheck = true;
                        tree.isexpand = false;
                        tree.complete = true;
                        tree.hasChildren = true;
                        tree.parentId = die.ParentId;
                        treeList.Add(tree);
                        var de4 = messagesendbll.GetDataItemList(die.ItemId);
                        foreach (DataItemDetailEntity dde in de4)
                        {
                            TreeEntity tree4 = new TreeEntity();
                            tree4.id = dde.ItemDetailId;
                            tree4.text = dde.ItemName;
                            tree4.value = dde.ItemCode;
                            tree4.Attribute = "score";
                            tree.AttributeValue = dde.ItemCode;
                            tree4.showcheck = true;
                            tree4.isexpand = false;
                            tree4.complete = true;
                            tree4.parentId = dde.ItemId;
                            treeList.Add(tree4);
                        }
                        set(die.ItemId);
                    }
                  
                }
                return Content(treeList.TreeToJson()); 
               
            } 
    

      前端js代码:

      //初始化数据
        function initControl() {
            var item = {
                showcheck: true,
                url: "../../SPManage/SP_WConsult/GetTree1Json",
            };
           
            $("div").treeview(item);
        }
    

      

  • 相关阅读:
    快速构建Windows 8风格应用22MessageDialog
    快速构建Windows 8风格应用20MediaElement
    Windows Phone SDK 8.0安装步骤
    快速构建Windows 8风格应用25数据绑定
    快速构建Windows 8风格应用24App Bar构建
    快速构建Windows 8风格应用21构建简单媒体播放器
    快速构建Windows 8风格应用23App Bar概述及使用规范
    sqlyog存储过程
    201751201 输入数字输出汉字读法
    考虑算法的时间效率
  • 原文地址:https://www.cnblogs.com/jiangxifanzhouyudu/p/7493157.html
Copyright © 2020-2023  润新知