This is a migrated thread and some comments may be shown as answers.

MVVM design best practice

1 Answer 77 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
cra
Top achievements
Rank 1
cra asked on 15 Dec 2015, 03:06 PM

Hello all,

I have a questions regarding model / page structure for what I am sure is a somewhat common pattern. But I am unable to find an answer for my specific needs.

 

I have a page that has an autocomplete to "search" for a person. Once that person is selected from the autocomplete, a form is displayed to show the detailed data about that person to be viewed / modified. Most of the data is displayed using simple html inputs and a few datepickers. However there is part of the data structure that displays multiple entries (think locations the person is associated with). This structure is best represented in a grid in my case.

 

Thus I am wondering if a single view model for the entire page makes most sense? So most of the fields on the page would be bound to say a "person" view model. And within that view model there would be a property that held the data returned from the second service call (after the initial autocomplete selection). So a "person" viewmodel would have a property called "data" and within that data property would be the data for the grid as well "data.locations". However when the grid is modified I am thinking that instead of syncing the entire view model only the grid data would need to be synced. So does that mean two viewmodels?

 

What is the general consensus for how to best structure this?

 

Thanks all.

1 Answer, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 17 Dec 2015, 08:46 AM

Hello Christopher,

 

I think that a single view model is the correct data presentation here. Notice that the syncing operation does not need to have a 1:1 mapping with the view model instance - you may sync only parts of it if necessary. 

 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MVVM
Asked by
cra
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Share this question
or