Best practice to access child properties in MVVM

4 posts, 1 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 26 Mar 2015 Link to this post

    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
  2. Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 30 Mar 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 30 Mar 2015 in reply to Petyo Link to this post

    To track means I use this.get("curRec.assessment") ? 

    Thanks
  5. Answer
    Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 01 Apr 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready