JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://github.com/janl/mustache.js/raw/master/mustache.js"></script>
<div id="container"></div>
JavaScript
$(function() {
var obj = {
x: 123,
points: [
{ name: "foo", y: 1.234567 },
{ name: "bar", y: 2.123456 },
{ name: "fax", y: 3.623415 }
],
toFixed: function() {
return function(num, render) {
return parseFloat(render(num)).toFixed(2);
}
}
};
var template = "{{x}}{{#points}}<br/>{{name}}, {{#toFixed}}{{y}}{{/toFixed}}{{/points}}";
$('#container').html(Mustache.render(template, obj));
});