Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call knockout custom binding update function

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 ?

like image 746
Tom Rider Avatar asked Nov 05 '12 04:11

Tom Rider


1 Answers

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.

like image 107
Jeff Mercado Avatar answered Oct 12 '22 07:10

Jeff Mercado