对“打造基于jQuery的高性能TreeView”的扩展
2009-10-28 00:00:00 来源:WEB开发网 /**//// <summary>
/// 添加一个子节点
/// </summary>
/// <param name="ti"></param>
/// <returns></returns>
public List<TreeItem> Add(TreeItem ti)
{
if (ChildNodes == null) ChildNodes = new List<TreeItem>();
ChildNodes.Add(ti);
return ChildNodes;
}
第三步:开始使用TreeView显示用服务器端生成的数据
好了,现在我们试试添加一个“一般处理程序”来生成相应的json子句。
添加 “GetTreeData.ashx” 代码如下:
ProcessRequest
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
TreeItem tdata = new TreeItem() { id = 0, checkstate = 0, complete = true, isexpand = true, showcheck = true, text = "所有项目", value = "" };
for (int i = 1; i <= 20; i++)
{
TreeItem t = new TreeItem() { id = i, text = i.ToString(), value = i.ToString(), showcheck = true, isexpand = false, complete = true };
if (i % 3 == 2)
{
//模拟多级树节点
t.ChildNodes = new List<TreeItem>();
t.ChildNodes.Add(new TreeItem() { id = i * 999 + 1, text = (i * 999 + 1).ToString(), value = (i * 999 + 1).ToString(), showcheck = true, complete = true });
t.ChildNodes.Add(new TreeItem() { id = i * 999 + 2, text = (i * 999 + 2).ToString(), value = (i * 999 + 2).ToString(), showcheck = true, complete = true });
t.ChildNodes.Add(new TreeItem() { id = i * 999 + 3, text = (i * 999 + 3).ToString(), value = (i * 999 + 3).ToString(), showcheck = true, complete = true });
}
if (t.hasChildren) t.ChildNodes[t.ChildNodes.Count - 1].complete = true;
tdata.Add(t);
}
tdata.ChildNodes[tdata.ChildNodes.Count - 1].complete = true;
context.Response.Write(tdata.ToJsonString());
}
赞助商链接