52,780
社区成员
发帖
与我相关
我的任务
分享public JsonResult GetGuestBooks()
{
List<jsondata> jsdata = new List<jsondata>();
for (int i = 1; i < 5; i++)
{
jsondata jd = new jsondata();
jd.id = "num" + i;
jd.text = "节点" + i;
jd.leaf = false;
for (int j = 1; j < 3; j++)
{
jsondata subjd = new jsondata();
subjd.id = "sub" + j;
subjd.text = "子节点" + j;
subjd.leaf = true;
jd.children.Add(subjd);
}
jsdata.Add(jd);
}
return Json(jsdata, JsonRequestBehavior.AllowGet);
}
public class jsondata
{
//定义jsondata类,存放节点数据
public string id;
public string text;
public bool leaf;
public List<jsondata> children = new List<jsondata>();//存放子节点
}
<script type="text/javascript">
Ext.onReady(function () {
Ext.QuickTips.init();
var mytree = new Ext.tree.TreePanel({
el: "grid",
animate: true,
title: "简单Extjs动态树",
collapsible: true,
enableDD: true,
enableDrag: true,
rootVisible: true,
autoScroll: true,
autoHeight: true,
width: 150,
lines: true,
//这里简简单单的loader的几行代码是取数据的,很经典哦
loader: new Ext.tree.TreeLoader({
dataUrl: "http://localhost:1683/Home/GetGuestBooks"
})
});
//根节点
var root = new Ext.tree.AsyncTreeNode({
id: "root",
text: "控制面板",
expanded: true
});
mytree.setRootNode(root);
mytree.render(); //不要忘记render()下,不然不显示哦
})
</script>
<div id="grid"></div>