I have a custom binding that is used to re-initialise a dom element whenever a field ("Type") is changed on the viewmodel. This is defined in an update callback.
<input type="text" data-bind="value: Value, initValueField: Type()" />
ko.bindingHandlers.initValueField = {
update:function (element, valueAccessor, allBindingsAccessor, viewModel) {
alert('Hello World');
}
};
See this jsFiddle for a stripped down demo.
As I understand it, one of the conditions for the update being invoked is the following:
The mechanics of custom bindings
Any time that another binding in the same data-bind attribute is triggered. This helps ensure things like the value is appropriate when the options are changed.
The issue I have is that this update callback is also called whenever the value on the viewmodel changes.
So...is it possible to either:
I found potential workarounds to the problem here:
Knockout.js Performance Gotcha #3 - All Bindings Fire Together
The options are:
init
to manage the updates manually.