With the click of a button, I want to update a d3js plot based on the values of two select elements. If I understand it right, simply calling the valueAccessor
should fire off the update function, which is not happening in my code.
I have the following custom binding:
ko.bindingHandlers.plotSvg = {
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
valueAccessor();
console.log("Update d3js plot");
}
};
And the view:
<div class="panel-body">
<div class="row">
<div class="col-xs-2">
<select class="form-control"
data-bind="options: $root.options,
optionsText: 'name',
value: firstSelectedOption">
</select>
</div>
<div class="col-xs-2">
<select class="form-control"
data-bind="options: $root.options,
optionsText: 'name',
value: secondSelectedOption">
</select>
</div>
<div class="col-xs-2 col-xs-offset-5">
<button class="btn btn-primary" data-bind="click: updatePlot">
Visualise
</button>
</div>
</div>
<div data-bind="plotSvg: updatePlot"></div>
</div>
updatePlot
is a function in the viewmodel, and all it does is print a value at the moment.
edit The javascript: http://pastebin.com/2qKLf6yf The view: http://pastebin.com/TPvmKgxL