I am using knockout.js. I have created a custom binding and applied it on anchor tag like this :
<a data-bind="custom : { param1 : 'text', param2: 'text' }">delete</a>
ko.bindingHandlers.custom = {
init: function (element, valueAccessor, allBindingsAccessor) {
alert("init");
},
update: function (element, valueAccessor, allBindingsAccessor) {
alert("update");
}
}
When i first load the page both the init
and update
functions called. But when i click on delete link update
function is not call. I want to call update function of my custom binding whenever i click over the delete link. What i am doing wrong here ?
The update function is only called initially when knockout applies the bindings and if any referenced observables are changed.
Your update function doesn't reference any observables and therefore doesn't get called again beyond the initial call.
If you want your function to be called when you click on it, you should use the click
binding instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With