This is the .haml code that contains my bindings. I removed bindings that weren’t relevant.
#date-extension
.filter-extension-container
.filter-extension-button
.button-close
#hand-graph-container{"data-bind" => "with:dateGraph"}
#x-axis
#hand-graph{"data-bind" => "foreach: {data:graphData}"}
%div{"data-bind" => "interactiveBar: $data"}
And I have the beginnings of a custom binding, like so.
ko.bindingHandlers.interactiveBar = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
debugger;
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
}
};
But when I look at viewModel, it is equal to the valueAccessor and is just the data object that I’m passing in. I’d like access to the dateGraph viewModel, and should be able to access it since I have used “with: graphData” according to the documentation.
Inside of a
foreachtheviewModelproperty is the data being bound at that scope level.There are a couple of options (assuming you are using Knockout 2.0):
pass
$parentinstead of$dataand access yourdateGraphobject viavalueAccessor()or the 5th argument to a binding handler is actually the binding context. The binding context will have
$data,$parent,$parents, and$rootproperties. You can see a description of the properties here.