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 subev
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>
</div>
<script id="person-template" type="text/x-kendo-template">
<li>
Index : <span data-bind="text:index"/> <br/>
<span data-bind="text:name" /> - <span data-bind="text:age" />
</li>
</script>
JavaScript
var viewModel = kendo.observable({
newPerson:{name:"", age:"",index:0},
people: [],
addPerson: function(){
this.people.push(this.newPerson);
this.set("newPerson",{name:"", age:"",index:this.people.length});
$("#name").focus();
}
});
kendo.bind($("#field-container"), viewModel);
$("#name").focus();