Handlebars is unable to read the JSON object that I am sending it as context.
Here is the function that makes the call to the Mustache template and gives it the context:
render: function() {
var source = $("#round").html();
var template = Handlebars.compile(source);
var context = JSON.stringify(this.model);
console.log(context);
var html = template(context);
$(this.el).html(html);
return this;
},
Here is the JSON object that I am passing it:
{"result":0,"friend1":{"firstName":"Ape","lastName":"Head","fbID":329018,"kScore":99,"profilePic":""},"friend2":{"firstName":"Ape","lastName":"Hands","fbID":32,"kScore":70,"profilePic":""}}
Here is the Handlebars template:
<script id="round" type="text/x-handlebars-template">
{{#with friend1}}
<h2>{{firstName}} {{lastName}}</h2>
{{/with}}
</script>
I get the following error:
Uncaught TypeError: Cannot read property firstName of undefined