我相信明天

导航

easyUI中树结构图的使用:

主要在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);

posted on 2015-08-06 12:14  我相信明天  阅读(458)  评论(0)    收藏  举报