Tree

浏览带有稳定标识的层级数据。

实时预览

正在加载预览…

参数配置

全部字段 9

TreeOptions

Styles · 0

TreeNodeItems

列表项 · 2
TreeNode
列表项 · 2
TreeNode
列表项 · 0
TreeNode
列表项 · 0
TreeNode
列表项 · 1
TreeNode
列表项 · 0

Go 代码

Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.Tree(c.Key("tree"), t, &s.Tree, nui.TreeOptions{Label: "Project files", Height: 260, Disabled: false})

使用说明

展开文件夹并选择项目,使用键盘查看层级导航。TreeState 在初始化时装入示例节点;真实文件树应在操作或后台任务完成后更新数据。

API 参考

func Tree(c *ui.Context, t Theme, s *TreeState, o TreeOptions) ui.Element

TreeOptions

源码
type TreeOptions struct {
	Label, EmptyText string
	Height           float32
	Disabled         bool
	OnChange         func()
	OnLoad           func(string, TreeTicket)
	Decoration
}
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

EmptyTextstring

Go 零值: ""

没有可显示数据时的文案。

Heightfloat32

Go 零值: 0

高度,单位为 DIP。

Disabledbool

Go 零值: false

禁用组件及其交互。

OnChangefunc()

Go 零值: nil

值发生变化时通知应用的回调。

OnLoadfunc(string, TreeTicket)

Go 零值: nil

请求加载子节点时通知应用的回调。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。

TreeNode

源码
type TreeNode struct {
	ID, Label string
	Icon      *ui.SVG
	Children  []TreeNode
	Lazy      bool
}
字段类型说明
IDstring

Go 零值: ""

唯一且稳定的业务标识。

Labelstring

Go 零值: ""

控件标签或可访问名称。

Icon*ui.SVG

Go 零值: nil

组件使用的 SVG 图标。

Children[]TreeNode

Go 零值: nil

子项目列表。

Lazybool

Go 零值: false

子节点需要延迟加载。