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

Accessing parent attributes in MVVM

3 Answers 182 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Grant asked on 22 Mar 2018, 09:43 AM

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

3 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 26 Mar 2018, 06:26 AM
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.
0
Grant
Top achievements
Rank 3
Iron
Iron
Iron
answered on 26 Mar 2018, 07:03 AM

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

0
David
Top achievements
Rank 1
answered on 10 May 2018, 05:33 PM

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. 

Tags
MVVM
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Konstantin Dikov
Telerik team
Grant
Top achievements
Rank 3
Iron
Iron
Iron
David
Top achievements
Rank 1
Share this question
or