Accessing parent attributes in MVVM

4 posts, 1 answers
  1. Grant
    Grant avatar
    106 posts
    Member since:
    Jul 2016

    Posted 22 Mar Link to this post

    Hi, 

    In short I want to know how to access the value of a parent's sibling attribute in the MVVM observable object. I do have a solution but I would like to know if the best option for me to use.

    http://dojo.telerik.com/AZEZixAs

    Thanks,
    Grant

  2. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2254 posts

    Posted 26 Mar Link to this post

    Hi Grant,

    Using the ViewModel is the correct way of accessing an object in this scenario. Note that you could get reference to the object directly:
    viewModel.person.name


    Best Regards,
    Konstantin Dikov
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Grant
    Grant avatar
    106 posts
    Member since:
    Jul 2016

    Posted 26 Mar in reply to Konstantin Dikov Link to this post

    Morning Konstantin, 

    Thanks for the confirmation, although I'd rather avoid using a direct reference so as to no loose any dependency links.

    See
    https://www.telerik.com/forums/viewmodel-attr-vs-viewmodel-get('attr')
    https://docs.telerik.com/kendo-ui/framework/mvvm/observableobject#dependent-methods

    Thanks so much,
    Grant

  4. David
    David avatar
    7 posts
    Member since:
    May 2013

    Posted 10 May Link to this post

    You could also traverse up the tree as well. 

    http://dojo.telerik.com/AZEZixAs/3

     

    Or can you tell me why this would be a bad idea? then you wouldn't have to reference the viewmodel by name directly. As you know where you are in the object it's just a case of going up the levels to come back down. 

Back to Top