I am trying to figure out how I can create a Kendo template that will loop through a JSON array returned by an AJAX request. Here is what the data object look likes:
[{"Id":5, "CreatedBy":"testuser1"},
{"Id":6,"Archived":false,"CreatedBy":"testuser2"},
{"Id":7,"Archived":false,"CreatedBy":"testuser3"}]
I would like to list just the CreatedBy field like this in a Kendo template:
Users List:
testuser1
testuser2
testuser3
Here is my attempt and it is not working:
<ul>
# for (var i = 0; i < data.length; i++) { #
<li>#= data[i].CreatedBy #</li>
# } #
</ul>
I just get a listing of undefined, undefined, undefined... and when I remove CreatedBy and just do data[i] I get each letter of each field listed. How do I access the actual CreatedBy values from the data object?
I was able to accomplish what I wanted by parsing it first. If anyone else has a better cleaner way of doing it please let me know.
If anyone is interested another update is that I found this in the kendo window documentation. If you set dataType to json the data gets parsed by jQuery for you and you don't need the $.parseJSON(data) line.