I’ve setup a view model like this:
function viewModel() {
var self = this;
self.voteOnItem = function (sender, e) { .. }
.
.
}
var model = new viewModel();
ko.applyBindings(model);
In my view, I have this inside of a template:
<script type="text/html" id="X">
<ul id="" data-bind="foreach:items">
<li>
<div style="float:left;">
<form action='Url' method="post" data-bind="submit:$parent.voteOnItem">
.
.
I’m getting an error “The value for a submit binding must be a function” for the mapping to voteOnItem, but voteOnItem is clearly a function… any idea why the error?
I would ensure that you are in the right scope when you are doing the
submitbinding.The error that you are getting is what you would see when
$parenthas novoteOnItemproperty (like if you put$parent.blah).An easy way to see is to just put a
<div data-bind="text: ko.toJSON($parent)"></div>near your binding to see the data at that level.The other thing to verify is that you have all of your tags closed and are not using any bad self-closing tags like
<span />.