<div id="app"></div>
<script>
compileTemplate = function (source) {
var template = Handlebars.compile(source);
function parseJSON(id, data) {
$(id).html(template(data));
}
parseJSON('#app', kingdom);
}
$.get('./templates/life.hbs', compileTemplate, 'html');
</script>
I'm trying to figure out how to rewrite this so that I don't have a nested function.
Here's what's going on.
- jQuery
$.get
usescompileTemplate
function to compile the hbs file for html output. - The
parseJSON
function uses the compiled template and inserts it into the element with the ID,app
.
This works just fine, except I can't use parseJSON by itself because it relies on the template variable. Hence, I'm stuck nested and can't figure out how to fix it. If I take the template variable out of the function, then it doesn't work because it relies on source in the function. Bah, I always run into callback hell.
There's probably a better way to do all of this, but this is where I'm at after doing some research and trying to figure it all out.