コード例 #1
0
        public static string GetJsonByModel(Tree t)
        {
            string json = "";
            bool   flag = UnitComboTreeDB.isHaveChild(t.id);/////////////////////////////////////////////////id为父节点的ID

            json = "{"
                   + "\"id\":\"" + t.id + "\","
                   + "\"name\":\"" + t.text + "\","
                   + "\"iconCls\":\"ok\",";
            if (t.@checked != null)
            {
                json += "\"checked\":true,";
            }
            json += "\"children\":";
            if (!flag)
            {
                json += "null}";
            }
            else
            {
                json += "[";
                IList <Tree> list = UnitComboTreeDB.getChild(t.id);
                // IList<Tree> list = UnitComboTreeDB.getChild(GID, t.id);
                foreach (Tree atom in list)
                {
                    if (atom != list[list.Count - 1])
                    {
                        json += GetJsonByModel(atom) + ",";
                    }
                    else
                    {
                        json += GetJsonByModel(atom);
                    }
                }
                json += "]}";
            }
            return(json);
        }