Hi I'm trying to set ko up so that on any click handler being called a little bit of custom code is run. Whats the easiest way to add some pre and post code to the 'click' bindings handler?
标签:
knockout.js
相关问题
- implementing html5 drag and drop photos with knock
- knockout checked binding doesn't update
- Knockout JS - Binding to array of observable Ints
- Knockout.js autocomplete bindingHandler [closed]
- Javascript in Edge only works with devtools open
相关文章
- Handle IE 9 & 10's clear button with Knockout
- jQuery Chosen doesn't update select options wh
- KnockoutJS property doesn't update when changi
- knockout.js - data-bind text default value
- Setting default values for computed Observable Kno
- Mapping: foreach binding work only the first time
- Knockout radio button binding with boolean
- Ajax Post and Redirect with Model Value MVC4
You can either create a custom binding that wraps the
click
binding or save off references to the originalinit
andupdate
functions of theclick
binding and replace the real one.You could either choose to execute some code in the
update
function which will be triggered when the model value is updated (either by the event handler attached in the init function or programmatically) or execute your code as part of the actual handler. It sounds to me like you want the latter.Your binding might look like:
I split out the pre/post code such that at run-time you could override
ko.bindingHandlers.click.preOnClick
orko.bindingHandlers.click.postOnClick
Here is a sample: http://jsfiddle.net/rniemeyer/PksAn/
If you need to run custom code in the update function, then you can split it out and run your pre and post code there and execute
originalUpdate
in between.