Knockout kendo grid template binding
http://stackoverflow.com/questions/10996945/knockout-kendo-grid-template-binding
HTML
<link rel="stylesheet" href="http://rniemeyer.github.com/knockout-kendo/css/kendo.common.min.css">
<link rel="stylesheet" href="http://rniemeyer.github.com/knockout-kendo/css/kendo.default.min.css">
<script src="http://knockoutjs.com/downloads/knockout-2.2.1.js"></script>
<script src="http://cdn.kendostatic.com/2012.3.1114/js/kendo.all.min.js"></script>
<script src="http://rniemeyer.github.com/knockout-kendo/js/knockout-kendo.min.js"></script>
<input data-bind="kendoDropDownList: { dataTextField: 'name', dataValueField: 'id', data: choices, value: selectedId }" />
<input data-bind="kendoDropDownList: { dataTextField: 'caption', dataValueField: 'id', data: selectedChoiceShapes, value: selectedShapeId }" />
<hr/>
Selected: <pre data-bind="text: ko.toJSON(selectedChoice, null, 2)"></pre>
<hr/>
CSS
div.hidden {display:none;}
JavaScript
var ViewModel = function() {
this.choices = ko.observableArray([
{ id: "1", name: "apple", shapes: [ { id: "5", caption: "circle" }, { id: "6", caption: "square" }] },
{ id: "2", name: "orange", shapes: [ { id: "5", caption: "circle" }] },
{ id: "3", name: "banana", shapes: [ { id: "5", caption: "circle" }, { id: "6", caption: "square" }, { id: "7", caption: "triangle" }] }
]);
this.selectedId = ko.observable("2");
this.selectedShapeId = ko.observable("5");
this.selectedChoice = ko.computed(function() {
var id = this.selectedId();
return ko.utils.arrayFirst(this.choices(), function(choice) {
return choice.id === id;
});
}, this);
this.selectedChoiceShapes = ko.computed(function () {
var selectedChoice = this.selectedChoice();
return selectedChoice && selectedChoice.shapes;
}, this);
};
ko.applyBindings(new ViewModel());