Reputation: 1594
I'm trying to find a way to change the click event on all my elements. I want to do something like this but I think how KO binds the click event its actually attached to the element and so changing the function has no effect.
viewModel.clickEvent = function(item){
logic
}
viewModel.clickEvent = newFunction;
<div data-bind="click: clickeEvent">MyButton</div>
I think that I need to use delegates but having a hard time figuring out how to do this. Could anyone post a basic example of how to do this with knockout?
Upvotes: 0
Views: 431
Reputation: 8987
If I have understood right. You could create a fake event handler that you can modify without modifying the actual event handler which is binded to the view.
var viewModel = {
clickEvent : function(item){
if(this.changableClickEvent)
this.changableClickEvent(item);
},
changableClickEvent : null
}
viewModel.changableClickEvent = function(){
// logic
alert('logic');
}
ko.applyBindings(viewModel);
Upvotes: 1