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

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

1 Answer 130 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jonathan M
Top achievements
Rank 1
Jonathan M asked on 03 Jan 2013, 09:50 PM
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: http://jsfiddle.net/pRMfN/1/

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,
Jonathan

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 07 Jan 2013, 06:02 PM
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>
</script>

The same approach is used in source binding to non array value example.
For convenience I updated your fiddle: http://jsfiddle.net/valchev/pRMfN/3/

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!
Tags
MVVM
Asked by
Jonathan M
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or