52,782
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript" src="../javascript/jquery.js"></script>
<script type="text/javascript" src="../javascript/jquery-treeview/jquery.treeview.js"></script>
<script type="text/javascript" src="../javascript/jquery-treeview/jquery.treeview.async.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#ajaxTree").treeview({ url: "TreeViewHandler.ashx" });
});
</script>
public void ProcessRequest (HttpContext context) {
HttpResponse response = context.Response;
HttpRequest request = context.Request;
response.ContentType = "application/json; charset=utf-8";
string json = string.Empty;
string param = GetQueryString(request, "root");
if (param == "source")
{
JQueryTreeNode node = new JQueryTreeNode(1, "Root");
IList<JQueryTreeNode> children = new List<JQueryTreeNode>();
children.Add(new JQueryTreeNode(11, "One"));
children.Add(new JQueryTreeNode(12, "Two", true));
children.Add(new JQueryTreeNode(13, "Three"));
node.children = children;
json = JavaScriptConvert.SerializeObject(node);
json = string.Format("[{0}]", json);
}
else
{
int id = 0;
if (int.TryParse(param, out id))
{
IList<JQueryTreeNode> children = new List<JQueryTreeNode>();
children.Add(new JQueryTreeNode(21, "22222222"));
//children.Add(new JQueryTreeNode(22, "3333333", true));
//children.Add(new JQueryTreeNode(23, "44444444444"));
json = JavaScriptConvert.SerializeObject(children);
}
}
response.Write(json);
}
private string GetQueryString(HttpRequest request, string key)
{
return (request.QueryString[key] != null) ? request.QueryString[key] : string.Empty ;
}