I’m getting started with Knockout. I can’t figure out how to setup up the binding in the valuesTemplate. What is the name of the current value of the iterator?
<div id="knock">
<p>Name: <input data-bind="value: Name" /></p>
<table>
<thead><tr><td>Value</td></tr></thead>
<tbody data-bind="template: {name: 'valuesTemplate', foreach: Values}" />
</table>
<script type="text/html" id="valuesTemplate">
<tr><td><input data-bind="value: value" /></td></tr>
</script>
</div>
<script type="text/javascript">
var data = {"Name":"Fish","Values":["Cod","Salmon","Perch","Glish"],"Id":"lookups/1"};
var viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
</script>
Inside of a jQuery Template, you can access the current context by using
$dataor$item.data, so like:However, if you are using observables, you are going to want your values array to contain objects rather than just strings.