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

Best practice to access child properties in MVVM

3 Answers 54 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 26 Mar 2015, 03:02 PM
Hello,
What's the best practice and the correct way to access child or sub properties on objects inside viewmodel.

For instance, in a viewmodel I have, it contains an object "curRec". this object has sub properties for instance, "curRec.assessment" (object) or "curRec.actions" (array).

In the viewmodel, shall I use this: this.get("curRec").assessment / this.get("curRec").actions or this.get("curRec.assessment") / this.get("curRec.actions") 

Thanks

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 30 Mar 2015, 11:43 AM
Hi,

there is no best practice or correct way in this case - all approaches should work as expected. Like we have suggested several times, you should use the getter accessor in case you need to track changes in the accessed field. 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bilal
Top achievements
Rank 2
answered on 30 Mar 2015, 11:51 AM
To track means I use this.get("curRec.assessment") ? 

Thanks
0
Accepted
Petyo
Telerik team
answered on 01 Apr 2015, 10:33 AM
Hello,

correct; you may also chain the get method calls.

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
Bilal
Top achievements
Rank 2
Answers by
Petyo
Telerik team
Bilal
Top achievements
Rank 2
Share this question
or