Unique ids in knockout.js templates

An alternative that does not rely on the order that the fields are bound is to have the binding set an id property on the data itself, which would need to be an observable. ko.bindingHandlers.uniqueId = { init: function(element, valueAccessor) { var value = valueAccessor(); value.id = value.id || ko.bindingHandlers.uniqueId.prefix + (++ko.bindingHandlers.uniqueId.counter); element.id = value.id; … Read more

Example of knockoutjs pattern for multi-view applications [closed]

There are a few directions that you could go with this one. One option is to call ko.applyBindings with distinct view models against separate DOM elements like: var viewModelA = { name: “Bob” }; var viewModelB = { price: 50 }; ko.applyBindings(viewModelA, document.getElementById(“aContainer”)); ko.applyBindings(viewModelB, document.getElementById(“bContainer”)); http://jsfiddle.net/9abgxn8k/ In this case, you would want to make sure … Read more

Can cleanNode() be used to clean binding?

ko.cleanNode is used internally by Knockout to clean up data/computeds that it created related to the element. It does not remove any event handlers added by bindings or necessarily understand if a binding made changes to the DOM. This can definitely cause problems like having multiple handlers attached to an element when it is subsequently … Read more