JSON

ExtAspNet应用技巧(二十二) - Ext4JSLint之JSON文件创建树控件(4)

字号+ 作者:H5之家 来源:H5之家 2015-09-30 14:02 我要评论( )

引子 Ext4JSLint是使用ExtAspNet来展示JSLint-Toolkit检查结果的开源项目。 JSLint-Toolkit是一个使用Rhino和JSLint的开源项目,可以对一个文件夹中的所有JavaS

完整的代码(根据错误设置节点颜色,同时为有错误的节点可回发):

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文件 的内容)。

下载全部源代码

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • ExtAspNet应用技巧(二十二) - Ext4JSLint之JSON文件创建树控件(2)

    ExtAspNet应用技巧(二十二) - Ext4JSLint之JSON文件创建树控件(2)

    2016-01-25 09:02

  • ExtAspNet应用技巧(二十二) - Ext4JSLint之JSON文件创建树控件(3)

    ExtAspNet应用技巧(二十二) - Ext4JSLint之JSON文件创建树控件(3)

    2015-10-28 15:05

  • PHP中JSON的应用技巧

    PHP中JSON的应用技巧

    2015-10-14 13:07

  • 关于JSON以及JSON在PHP中的应用技巧(2)

    关于JSON以及JSON在PHP中的应用技巧(2)

    2015-10-05 09:14

网友点评