165
rated 0 times
[
167]
[
2]
/ answers: 1 / hits: 8725
/ 11 Years ago, fri, december 6, 2013, 12:00:00
I have a mustache template and I would like to call some function on the mustache variables ({{name}} in this case). Specifically, I want to call toLowerCase() method on the name variable.
<tbody>
<script id=mytemplate type=text/template>
{{#cat}}
<tr data-index={{age}}-{{name}}></tr>
{{/cat}}
</script>
</tbody>
I tried looking in the mustache docs but I couldn't find out how to do this. I tried doing
<tr data-index={{age}}-{{name.toLowerCase()}}></tr>
<tr data-index={{age}}-{{name}}.toLowerCase()></tr>
But I'm not getting what I expect. I render the template with this code which gets triggered on document ready.
$(function() {
$.getJSON('/cats.json', function(data){
var template = $(#mytemplate).html();
var view = Mustache.to_html(template, data);
$(tbody).html(view);
});
})
More From » jquery