Question about accessing a hierarchic observable

2 posts, 0 answers
  1. Randall
    Randall avatar
    1 posts
    Member since:
    May 2013

    Posted 14 Oct 2014 Link to this post

    I have a hierarchic javascript object that I pass to kendo observable. Is it better to use get and set on the top-level object with dotted path into the object?
        viewModel.get('current.prType');


    Or is it better to use get and set on the lowest level of the hierarchy?
        viewModel.current.get('prType');

    Here is a simple jsfiddle sample that demonstrates that both forms work. I just want to know if there is any difference that I should be aware of.

    http://jsfiddle.net/ebLxk7at/


    Thanks,
    randall.

  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 16 Oct 2014 Link to this post

    Hello Randall,

    Using the full path is preferred. The other approach works because MVVM in some scenarios needs to search in depth to find such property.

    Here is another example that should show you better the difference.

    http://jsfiddle.net/ebLxk7at/1/


    Regards,
    Petur Subev
    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
Back to Top