Success!!!
I've managed to dynamically bind a custom binding to an element.
First I have an observable:
value: ko.observable()
Then I create a custom binding called 'tooltip':
ko.bindingHandlers.tooltip = {
init: function(element, valueAccessor,
allBindingsAccessor, viewModel) {
console.log("init " + element );
},
update: function(element, valueAccessor, viewModel) {
var handle = $(element);
var value = ko.utils.unwrapObservable(valueAccessor());
console.log("update " + value );
}
};
Then I attach that binding to a slider handle:
var handle = slider.slider().find(".ui-slider-
handle").first();
$(handle).attr("data-bind", "tooltip: value"); //
dynamically add the data-bind attr to that handle, binding to the
'value' model
ko.applyBindings( Sirtrack.Filters.lowerlimit, $
(firsthandle)[0] ); // tell ko to bind the two
It looks very nice and elegant to me (I'm loving ko!). It seems to
work, but I need to do some more testing.
Cheers,
Emanuele @ZiglioNZ
On Feb 21, 9:51 am, Emanuele Ziglioli <
theb...@emanueleziglioli.it>
wrote: