How to invoke a method when all the custom bindings are applied in knockoutjs?

52 Views Asked by At

I am working on KnockoutJS with jQuery. I need to apply custom binding say myBinding on multiple views.

I have a case where multiple views are bound with myBinding, a JS method need to be called which will pass some viewmodel data from these views.

I don't have control on how many templates will be there on a page. So I am looking for some handle which keeps track of all the templates on page which use myBinding. Once all the views on page are loaded, the json passed along with the myBinding would be sent in an AJAX request.

HTML templates:

<div id="myDiv1" data-bind="myBinding:myJson"> </div>
<div id="myDiv2" data-bind="myBinding:myJson"> </div>
<div id="myDiv3" data-bind="myBinding:myJson"> </div>
<div id="myDiv4" data-bind="myBinding:myJson"> </div>

JS Code:

ko.bindingHandlers.myBinding = {
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext){
    },
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext){
    }
};

Once all these bindings are called I want to call following update function:

//JS Code
function updateBindingTemplates{
    // do something
}

Is there any way to achieve the same thing?

Thanks.

0

There are 0 best solutions below