Skip to content

Get struct filed value from user inputed #747

Closed Answered by kkoreilly
ddkwork asked this question in Q&A
Discussion options

You must be logged in to vote

You can just directly access the field of the underlying struct. For example:

type Person struct {
   Name string
   Age int
}
p := &Person{}
giv.NewStructView(par).SetStruct(p)
...
// when you want to access the data of the struct
fmt.Println(p.Name)

If you want to be notified when the struct view changes, just add an OnChange event handler:

type Person struct {
   Name string
   Age int
}
p := &Person{}
sv := giv.NewStructView(par).SetStruct(p)
sv.OnChange(func(e events.Event) {
    fmt.Println(p.Name)
})

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by kkoreilly
Comment options

You must be logged in to vote
1 reply
@kkoreilly
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants