码迷,mamicode.com
首页 > 其他好文 > 详细

easyUI中树结构图的使用:

时间:2015-08-06 13:03:25      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

主要在Json字符串的生成,必须生成tree所需要的特定json字符格式。创建EasyTreeData类用于生成json字符串

namespace JPKL.Common

{

    [DataContract]

    [Serializable]

    public class EasyTreeData

    {/// <summary>

        /// ID

        /// </summary>

        [DataMember]

        public string id { get; set; }

 

        /// <summary>

        /// 节点名称

        /// </summary>

        [DataMember]

        public string text { get; set; }

 

        /// <summary>

        /// 是否展开

        /// </summary>

        [DataMember]

        public string state { get; set; }

 

        /// <summary>

        /// 图标样式

        /// </summary>

        [DataMember]

        public string iconCls { get; set; }

 

 

        /// <summary>

        /// 子节点集合

        /// </summary>

        [DataMember]

        public List<EasyTreeData> children { get; set; }

 

        /// <summary>

        /// 默认构造函数

        /// </summary>

        public EasyTreeData()

        {

            this.children = new List<EasyTreeData>();

            this.state = "open";

        }

 

        /// <summary>

        /// 常用构造函数

        /// </summary>

        public EasyTreeData(string id, string text, string iconCls = "", string state = "open")

            : this()

        {

            this.id = id;

            this.text = text;

            this.state = state;

            this.iconCls = iconCls;

        }

 

        /// <summary>

        /// 常用构造函数

        /// </summary>

        public EasyTreeData(decimal id, string text, string iconCls = "", string state = "closed")

            : this()

        {

            this.id = id.ToString();

            this.text = text;

            this.state = state;

            this.iconCls = iconCls;

        }

    }

}

如何使用EasyTreeData类?

List<EasyTreeData> treeList = new List<EasyTreeData>();//创建一个树类集合

            List<CATEGORY> category = CategoryService.GetCategorys(id);//获取所需要数据的集合

            foreach (CATEGORY info in category)//将所需要数据的集合转化为树类集合

            {

                treeList.Add(new EasyTreeData(info.CATEGORY_ID, info.CATEGORY_NAME, "icon-user"));

            }

            string json = new JavaScriptSerializer().Serialize(treeList);

            return Content(json);

easyUI中树结构图的使用:

标签:

原文地址:http://www.cnblogs.com/woxiangxin/p/4707640.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!