Kendo UI - Unable to get at index
While using the kendo source binding to bind to an array, there doesn't appear to be any way to get at the index of the current item being bound to within the template.
by seamuskc
HTML
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.default.min.css">
<script src="http://cdn.kendostatic.com/2012.1.322/js/kendo.all.min.js"></script>
<div id="field-container">
<ul id="person-list" data-template="person-template" data-bind="source: people"></ul>
First Name: <input name="name" id="name" data-bind="value:newPerson.name" />
Age: <input name="age" data-bind="value:newPerson.age" />
<button data-bind="click:addPerson" class="k-button">Add</button>
<script id="person-template" type="text/x-kendo-template">
<li>
<span data-bind="text:name" /> - <span data-bind="text:age" />
<!-- ???? How to get at the index of the current array item here ????-->
<input name="person[currentIndexHere].name" type="hidden" data-bind="value:name">
<input name="person[currentIndexHere].age" type="hidden" data-bind="value:age" >
</li>
</script>
</div>
JavaScript
var viewModel = kendo.observable({
newPerson:{name:"", age:""},
people: [],
addPerson: function(){
this.get("people").push(this.newPerson);
this.set("newPerson",{name:"", age:""});
$("#name").focus();
}
});
kendo.bind($("#field-container"), viewModel);
$("#name").focus();