需要帮助在运行时更新树小部件,正如这里所建议的fyne问题似乎在小部件上使用Refresh()函数,它将同步存储在地图中的数据更改,这是代码:listpackage main//______________________________________________________________________________import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/widget" dbg "github.com/fatih/color")//______________________________________________________________________________var content *fyne.Containervar tree *widget.Treevar list map[string][]string//______________________________________________________________________________func main() { myApp := app.New() myWindow := myApp.NewWindow("List") makeTree() top := widget.NewLabel("Items' list::") bottom := widget.NewButton("Update list", updateList) content = container.New(layout.NewBorderLayout(top, bottom, nil, nil), top, tree, bottom, ) myWindow.SetContent(content) myWindow.Resize(fyne.NewSize(480, 600)) myWindow.ShowAndRun()}//______________________________________________________________________________func makeTree() { list = map[string][]string{ "": {"A"}, "A": {"B", "D"}, "B": {"C"}, "C": {"abc"}, "D": {"E"}, "E": {"F", "G"}, } tree = widget.NewTreeWithStrings(list) tree.OnSelected = func(id string) { dbg.Green("Tree node selected: %s", id) } tree.OnUnselected = func(id string) { dbg.Green("Tree node unselected: %s", id) } tree.OpenAllBranches()}//______________________________________________________________________________func updateList() { dbg.Green("UpdateList") list = map[string][]string{ "": {"A"}, "A": {"B"}, "B": {"C"}, } tree.Refresh()}谢谢
1 回答

湖上湖
TA贡献2003条经验 获得超2个赞
这是一个静态帮助程序函数,因此不会真正按照您想要的方式进行更新。如果可以使用,则可以指向数据结构,它将自动更新。NewTreeWithStrings
NewTree
- 1 回答
- 0 关注
- 114 浏览
添加回答
举报
0/150
提交
取消