<ul id="et" class="easyui-tree">
</ul>
$(function () {
$('#et').tree({
url: 'http://localhost:2148/Main/GetMenu',
checkbox: true
});
public JsonResult GetMenu()
{
//格式必须是一个集合
List<TreeModel> litm = new List<TreeModel>();
TreeModel mf = new TreeModel();//父节点
mf.id = "id";
mf.text = "管理";
List<TreeChildrenModel> li = new List<TreeChildrenModel>();//子节点
foreach (var item in List)
{
TreeChildrenModel tcm = new TreeChildrenModel();
tcm.id = item.id.ToString();
tcm.text = item.title;
tcm.@checked = true;
tcm.attributes = new Attributes() { url = "" };
li.Add(tcm);
}
mf.children = li;
litm.Add(mf);
return Json(litm);
}
}
#region easy ui 动态树需要model
public class TreeModel
{
public string id { get; set; }
public string text { get; set; }
public bool @checked { get; set; }
public List<TreeChildrenModel> children { get; set; }
}
public class TreeChildrenModel
{
public string id { get; set; }
public string text { get; set; }
public bool @checkbox{ get; set; }
public Attributes attributes { get; set; }
}
public class Attributes
{
public string url { get; set; }
}
#endregion