/// <summary> /// 是否叶节点 /// </summary> /// <param name="node">树节点</param> protected virtual bool IsLeaf(ZorroTreeNode node) { if (node.Key.IsEmpty()) { return(true); } return(_data.All(t => t.ParentId != node.Key)); }
/// <summary> /// 添加子节点 /// </summary> /// <param name="node">树节点</param> private void AddChildren(ZorroTreeNode node) { if (node == null) { return; } node.Children = GetChildren(node.Key).Select(ToNode).ToList(); foreach (var child in node.Children) { AddChildren(child); } }
/// <summary> /// 初始化叶节点状态 /// </summary> /// <param name="node">树节点</param> protected virtual void InitIsLeaf(ZorroTreeNode node) { node.IsLeaf = false; if (_async) { return; } if (IsLeaf(node)) { node.IsLeaf = true; } }
/// <summary> /// 转换为树节点 /// </summary> /// <param name="dto">树形数据传输对象</param> protected virtual ZorroTreeNode ToNode(TreeDto dto) { var result = new ZorroTreeNode() { Key = dto.Id, Title = dto.Text, Icon = dto.Icon, Disabled = !dto.Enabled.SafeValue(), Expanded = dto.Expanded.SafeValue(), Checked = dto.Checked.SafeValue(), DisableCheckbox = dto.DisableCheckbox.SafeValue(), Selectable = dto.Selectable.SafeValue(), Selected = dto.Selected.SafeValue() }; InitIsLeaf(result); return(result); }