javascript - Handlebars not rendering JSON context data, getting empty template -


i having strange issue handlebars compiling template properly, when passing context data, resulting fields in html blank. i've confirmed json data javascript object , not string. apologies if has been answered elsewhere. saw lot of answers json string needing actual object, i've stated, not case.

template:

<script type="text/x-handlebars-template" id="items-template"> {{#each downloads}} <div class="download-item">     <h3>{{pagetitle}}</h3>     <p>{{description}}</p> </div> {{/each}} </script> 

js:

var source = $("#items-template").html(); var template = handlebars.compile( $.trim(source) ); var html = template({     downloads:[         {pagetitle:'title', description:'the description'},         {pagetitle:'title', description:'the description'},         {pagetitle:'title', description:'the description'}     ] }); 

result of html (only 1 single blank item):

<div class="download-item">     <h3></h3>     <p></p> </div> 

any insight appreciated. if figure out before sees this, i'll sure post update.

you should use this

{{#each downloads}} <div class="download-item">     <h3>{{this.pagetitle}}</h3>     <p>{{this.description}}</p> </div> {{/each}} 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -