JSFiddle - React, Tailwind, and code Playground
by fguillen
HTML
<script src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script type='text/template' id='src'>
<ul>
{{#each model._revs_info}}
{{#if_eq status compare="available"}}
{{debug ../../model}}
<li>#list/{{../../model.id}}/{{rev}}</li>
{{/if_eq}}
{{/each}}
</ul>
</script>
JavaScript
Handlebars.registerHelper('if_eq', function(context, options) {
if (context == options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});
var data={
model:{
id:"the_model_id",
_revs_info:[
{status:"available",rev:1},
{status:"unavailable",rev:2},
{status:"available",rev:3}
]
}
}
var source = $("#src").html();
var template = Handlebars.compile(source);
$("body").append( template(data) );