I’m trying to create a widget that I can use with Knockout.js
I’ve taken the jquery demo widget for this example from here:
My code is in a fiddle here
What I am trying to do is to bind to a custom event within the object:
this._trigger("random", event, colors)
so in my knockout binding I have this code:
ko.utils.registerEventHandler(element, "random", function (event) {
alert("Got to here");
});
I expected the alert to fire when the trigger is fired, but it doesn’t occur.
However if instead I bind to click.colorize as in this modified code then the alert does fire.
Can anyone explain why the triggered event isn’t picked up?
The solution is to set the widget’s eventPrefix – see here
and then raise the event as before:
catching it as follows:
Note the concatenation of “color” and “foo”.