I have some working code which I am trying to convert to use the MVVM pattern. My code looks like the following:
To start with, I have a div tag like the following:
<div id="MyDiv" data-template="template" ></div>
My template looks like the following:
<script type="text/x-kendo-template" id="template">
<table>
<tr>
<td>My Numbers: </td>
#for (var i = 0; i < data.length; i++){#
<td><input type="text" value=#= data[i] # /></td>
#}#
</tr>
</table>
</script>
Finally the following script provides data to the template:
<script>
var rowTemplate = kendo.template($("#template").html());
function display() {
$("#MyDiv").html(rowTemplate({
data: ["1.2", "2.3", "3.4"]
}));
}
display();
</script>
When I run, the output shows the numbers 1.2, 2.3 and 3.4 in 3 inputboxes (each of which appears in 3 separate <td> tags) against a label, like the following:
My Numbers: 1.2 2.3 3.4
I have been trying to convert the above code to an MVVM pattern, but somewhy not getting it right. Could someone please guide me how to do this correctly?