MVVM design best practice

2 posts, 0 answers
  1. cra
    cra avatar
    16 posts
    Member since:
    Jun 2012

    Posted 15 Dec 2015 Link to this post

    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.

  2. Petyo
    Petyo avatar
    2444 posts

    Posted 17 Dec 2015 Link to this post

    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. 


    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top