Can someone please help me out? I'm finding this task more difficult than it should be, so I must be overlooking something simple...
I am working with a variable that is acting as an underscore template. Here is an example of the code snippet:
var template = '<% _.each(favorites, function(value, key) { %> <li><%= key %>: <%= value %></li> <% }); %>';
So what exactly is in 'favorites'? It is data coming from a JSON object that resembles something like this (excluding other JSON data).
"favorites" : [
{ "food" : "shrimp" },
{ "drink" : "none" }
]
I just can't seem to understand why I can't get the key/value pairs to display properly in the template. All I want is for the output to look like this:
<li>food: shrimp</li>
<li>drink: none</li>
Where have I gone wrong?