easyui树mysql_easyUI中树结构图的使用:

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

namespace JPKL.Common

{

[DataContract]

[Serializable]

public class EasyTreeData

{///

/// ID

///

[DataMember]

public string id { get; set; }

///

/// 节点名称

///

[DataMember]

public string text { get; set; }

///

/// 是否展开

///

[DataMember]

public string state { get; set; }

///

/// 图标样式

///

[DataMember]

public string iconCls { get; set; }

///

/// 子节点集合

///

[DataMember]

public List children { get; set; }

///

/// 默认构造函数

///

public EasyTreeData()

{

this.children = new List();

this.state = "open";

}

///

/// 常用构造函数

///

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

: this()

{

this.id = id;

this.text = text;

this.state = state;

this.iconCls = iconCls;

}

///

/// 常用构造函数

///

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 treeList = new List();//创建一个树类集合

List 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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值