Example #1
0
        public JSONTreeNode Find(List <JSONTreeNode> sourceList, string id)
        {
            JSONTreeNode result = null;

            result = sourceList.Find(n => n.ID == id);
            if (result == null)
            {
                foreach (JSONTreeNode child in sourceList)
                {
                    result = child.Find(id);
                    if (result != null)
                    {
                        break;
                    }
                    else if (child.Nodes.Count > 0)
                    {
                        result = Find(child.Nodes, id);
                        if (result != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(result);
        }
Example #2
0
        public void ClearNodes(string pid)
        {
            JSONTreeNode node = this;

            if (node.ID != pid)
            {
                node = this.Nodes.Find(n => n.ID == pid);
            }
            if (node != null)
            {
                node.Nodes.Clear();
            }
        }
Example #3
0
        private void ModifyTempNodes()
        {
            int currentCount = this.TempNodes.Count;

            JSONTreeNode[] nodes = new JSONTreeNode[currentCount];
            this.TempNodes.CopyTo(nodes);
            foreach (JSONTreeNode item in nodes)
            {
                AppendNode(item.ParentID, item.ID, item.Title, item.IsExpand, item.ShowCheckBox, item.CheckedSign);
            }
            if (currentCount != this.TempNodes.Count)
            {
                ModifyTempNodes();
            }
        }
Example #4
0
        public void AppendNode(string pid, string id, string title, string value, bool isExpand, bool showCheckBox, int checkedSign)
        {
            JSONTreeNode node = this;

            if (node.ID != pid)
            {
                node = this.Find(pid);
            }
            if (node == null)
            {
                if (this.TempNodes.Find(n => n.ID == id) != null)
                {
                    return;
                }
                // 若父节点为空,把此节点放入临时节点集合里
                node = new JSONTreeNode(id, title, isExpand, showCheckBox);
                if (showCheckBox)
                {
                    node.CheckedSign = checkedSign;
                }
                node.ParentID = pid;
                node.Value    = value;
                this.TempNodes.Add(node);
            }
            else
            {
                //若存在此ID的节点,更新节点信息
                JSONTreeNode child = this.Find(id);
                if (child == null)
                {
                    child = new JSONTreeNode(id, title, isExpand, showCheckBox);
                    if (showCheckBox && checkedSign > 0)
                    {
                        child.CheckedSign = checkedSign;
                    }
                    child.Value = value;
                    node.Nodes.Add(child);
                    this.TempNodes.RemoveAll(n => n.ID == id);
                }
                else
                {
                    child.Title    = title;
                    child.IsExpand = isExpand;
                }
                node.HasChild = true;
                node.Loaded   = true;
            }
        }
Example #5
0
 public static string ToString(JSONTreeNode node)
 {
     return(string.Format("[{0}]", node.ToString()));
 }
Example #6
0
 public JSONTree(string id, string title)
 {
     this.Root = new JSONTreeNode(id, title, true);
 }