I have this HTML template and jsRender:
<div id="output"></div> <script id="template" type="text/x-jsrender"> <ul> {{for}} <li>{{:name}} likes to wear {{:shirtColor}} shirts</li> {{/for}} </ul> </script>β
and I have javascript (jQuery):
var data = [{ name: 'Dan Wahlin', shirtColor: 'white'}, { name: 'John Papa', shirtColor: 'black'}, { name: 'Scott Guthrie', shirtColor: 'red'} ] ; $('#output').html($('#template').render(data));β
As you can see, this is an example from John Papa. That is, I changed it a little. But it does not work properly. The reason is that jsRender expects a root object in Json, as in Johnβs example, where {{for}} is {{for people}}, and the data object looks like this:
var data = { people: [{ name: 'Dan Wahlin', shirtColor: 'white'}, { name: 'John Papa', shirtColor: 'black'}, { name: 'Scott Guthrie', shirtColor: 'red'} ] } ;
In my ASP.NET MVC controller, Json is not returned with a root object. How can I make this work? Change Json format (and how to do it?)? or am I doing something wrong in my jsRender code?
Thanks in advance!
source share