I am using the underscore.js template library with my backbone example. My template looks like this:
<script id="results-template" type="text/template">
<h2><%= title %></h2>
</script>
The JSON object looks like this:
{"src":"placeholder.jpg","title":"an image placeholder","coordinates":[0,0],"tags":["untagged"],"location":"home"}
I am trying to parse this object through my template but the error I get through my console is:
Uncaught ReferenceError: title is not defined
What am I doing wrong? Live fiddle is here: http://jsfiddle.net/amit_e/muLjV/46/
your problem is this:
this needs to be
reason: your
JSON.stringify()will put the whole myPhoto model as a json string. now, Backbone has this function to output json as a json object, so you can usemodel.toJSON()updated jsfiddle: http://jsfiddle.net/saelfaer/muLjV/50/