Detail view

Now that we have a data model built, let's display the data that's loaded. Starting with the email detail view, we will make use of Walk's declarative API, DataBinder. This allows us to avoid having to manually set the data on each label every time a new message is loaded. To work correctly, we also need to create a walk.DataBinder to assign to—this will handle the actual bindings:

emailDetail *walk.DataBinder

Then we can update the Composite widget that displays the email information to use this data binding. Let's also set the default content through the DataSource field. This information will come from the model, which we will initialize shortly:

DataBinder: DataBinder{
AssignTo: &emailDetail,
DataSource: model.Server.CurrentMessage(),
},

Then, each item simply has its static Text field changed to an appropriate Bind() call; the parameter will be the name of the field on an client.EmailMessage type described in the View model section:

Text:       Bind("Subject"),

For the Date field, we can't directly bind a time.Time type, so use the DateString() helper instead:

Text:       Bind("DateString"),

And finally, let's create a helper method that will allow us to update the email message that is currently bound:

func (g *GoMailUIBrowse) SetMessage(email *client.EmailMessage) {
g.emailDetail.SetDataSource(email)
g.emailDetail.Reset()
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.68.18