Inconsistent behavior when binding to a child observable object vs the parent view model object

2 posts, 0 answers
  1. Jonathan M
    Jonathan M avatar
    16 posts
    Member since:
    Sep 2012

    Posted 03 Jan 2013 Link to this post

    I have a run into an issue that is causing problems for us on our project. Instead of going into a lengthy description, here is a jsFiddle that demonstrates the issue:

    What I'd expect to happen when you click the button is that both divs are refreshed to output true, but instead only the div that is bound to the viewModel directly is refreshed, while the div that is bound to the child observable object is not.

    Am I doing something wrong? Is this behavior by design? I realize that this is a contrived example and I could use spans with text bindings instead of templates to accomplish the same thing here, but on our real-world project this is an issue because we must use templates on a particular page (for various reasons) and we'd like to bind to a child object to reduce the number of times a template is re-rendered to improve performance (there are other child objects that are updated independently of the one in question), but when we do, the template is only called once, and not refreshed each time a value inside it changes.

    Thanks for any assistance,
  2. Alexander Valchev
    Alexander Valchev avatar
    2887 posts

    Posted 07 Jan 2013 Link to this post

    Hello Jonathan,

    You should bind the isSo field in the childTemplate:
    <script id="childTemplate" type="text/html">
      <p>Child source binding: <span data-bind="text: isSo"></span></p>

    The same approach is used in source binding to non array value example.
    For convenience I updated your fiddle:

    Kind regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top