Reputation: 23
I am working on Page which consist of 3 Lists and 1 Pulse control. List control made using Knockout simplegrid plugin and i made pulse control using only knockout. Both controls use different ViewModels. The problem is when i place my pulse control above the listing control, the pulse control working fine. But when i put it below the list control , the data bind on every element fails i.e. data bind for inputs,buttons not working. I checked console but i found no errors. I also used chrome knockout extension it also not showing any error. Please provide what can be the possible scenarios by which problem is generating.
Upvotes: 2
Views: 3190
Reputation: 1139
Probably because you are overriding when you apply bindings. You can fix this by telling Knockout the root element at which it should apply bindings so that your view models don't interfere with each other.
ko.applyBindings(viewModelA, document.getElementById("controlone"));
ko.applyBindings(viewModelB, document.getElementById("controltwo"));
From knockout docs: http://knockoutjs.com/documentation/observables.html
Optionally, you can pass a second parameter to define which part of the document you want to search for data-bind attributes. For example, ko.applyBindings(myViewModel, document.getElementById('someElementId')). This restricts the activation to the element with ID someElementId and its descendants, which is useful if you want to have multiple view models and associate each with a different region of the page.
Upvotes: 2