I'm struggling to make this work, even though I feel like it should be possible. What I am trying to do is use underscore and jQuery to apply a template to an array of objects. Here is the code snippet that I have:
var template = _.template($("script.template").html());
var jA = data.jsonArray;
$("#results").html(_.template(template(jA)));
My expectation was that the template would be applied to each object in the array, but unfortunately, it's not working as expected.
When I tried using a loop, it worked fine, but it seems like an unnecessary step.
$.each(jA, function(index,value){
$("#results").append(_.template(template(value)));
});
Is there something I'm missing that's causing this issue, or do I really have to resort to using a loop? (jA is confirmed to be a JSON array)
Thank you for your help :)