完整的代码(根据错误设置节点颜色,同时为有错误的节点可回发):
001.private void ResolveMenuTree(JSONArray ja, List<string> treePathList, bool showAllErrors, ExtAspNet.TreeNodeCollection nodes)
002.{
003. for (int i = 0; i < ja.Count; i++)
004. {
005. JSONObject kid = ja[i] as JSONObject;
006. string name = kid.getString("name");
007. // 当前路径,如果basePath存在说明是根目录
008. if (kid.has("basePath"))
009. {
010. treePathList.Add(kid.getString("basePath"));
011. }
012. else
013. {
014. treePathList.Add(name);
015. }
016. string currentPath = GetTreePath(treePathList);
017. // 获取JSLint错误数
018. JSONArray errors = kid.getJSONArray("errors");
019. int errorCount = errors.getInt(0);
020. int criticalErrorCount = errors.getInt(1);
021. if (showAllErrors)
022. {
023. if (errorCount > 0)
024. {
025. name += String.Format(" ({0})", errorCount);
026. }
027. }
028. else
029. {
030. if (criticalErrorCount > 0)
031. {
032. name += String.Format(" ({0})", criticalErrorCount);
033. }
034. }
035. string type = kid.getString("type");
036. // 如果文件夹中没有文件,则不添加此文件夹
037. if (type == "folder" && kid.getInt("fileCount") == 0)
038. {
039. treePathList.RemoveAt(treePathList.Count - 1);
040. continue;
041. }
042. ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
043. nodes.Add(node);
044. node.Text = name;
045. //node.ToolTip = currentPath;
046. // 节点的显示颜色
047. string style = "";
048. if (showAllErrors)
049. {
050. if (errorCount == 0)
051. {
052. style = "color:green;";
053. }
054. else
055. {
056. if (criticalErrorCount == 0)
057. {
058. style = "color:#FF9900;";
059. }
060. else
061. {
062. style = "color:#FF0000;";
063. }
064. }
065. }
066. else
067. {
068. if (criticalErrorCount != 0)
069. {
070. style = "color:#FF0000;";
071. }
072. else
073. {
074. style = "color:green;";
075. }
076. }
077. node.Text = String.Format("<span qtip=\"{2}\" style=\"{0}\">{1} </span>", style, node.Text, currentPath);
078.
079. if (type == "folder")
080. {
081. node.SingleClickExpand = true;
082. ResolveMenuTree (kid.getJSONArray("kids"), treePathList, showAllErrors, node.Nodes);
083. }
084. else
085. {
086. node.Leaf = true;
087. if (showAllErrors)
088. {
089. if (errorCount != 0)
090. {
091. node.EnablePostBack = true;
092. node.CommandName = currentPath;
093. }
094. }
095. else
096. {
097. if (criticalErrorCount != 0)
098. {
099. node.EnablePostBack = true;
100. node.CommandName = currentPath;
101. }
102. }
103. }
104. treePathList.RemoveAt(treePathList.Count - 1);
105. }
106.}
下一章将讲述如何点击左侧树节点时更新中间的Grid控件,并加载右侧的IFrame(即JavaScript文件 的内容)。
下载全部源代码