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