So I have a page in my application that uses a fairly standard nested model implementation, along the lines of the standard Customer -> Order -> OrderLineItems type. The difference for me is that the model at OrderLineItems is pretty complex.
In my code, both with observable arrays as well as observables, in order to update my view correctly, I find that I wind up calling "myObservable.valueHasMutated()" quite a lot.
It's a gut feel that having to do this manually isn't quite as it should be--but I'm not sure where to look to know what might need changing. So a few questions:
- Is this just normal for "deep/big" models?
- Is there something obvious I might look for to address this?
- Is there an example on the web of complex models like this implemented with KO?
An example of what I have in my viewmodel:
self.projectsVisible = ko.observable(false);
self.toggleProjectVisibility = function () {
self.projectsVisible(!self.projectsVisible());
self.projectsVisible.valueHasMutated();
};
That's tied to a button element, and a DIV:
<div data-bind="visible: projectsVisible">
<table>
<thead data-bind="template: {name: 'projectHeader'}"></thead>
<tbody data-bind="template: {name: 'project', foreach: projects}"></tbody>
</table>
</div>
<button type="button" data-bind="click: toggleProjectVisibility">
Toggle Projects On/Off
</button>